LoadAllProduct에서 변수를 전달하고 싶습니다. AsyncTask를 Fragment1 extends Extension으로 확장하지만 어떻게 할 수 있는지 잘 모릅니다.액티비티의 변수를 액티비티 프래그먼트로 전달
가 가public class MainChauffeur extends FragmentActivity implements TabListener{
JSONParser jParser = new JSONParser();
.
.
.
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.activity_main_chauffeur);
LoadAllProduct a=new LoadAllProduct();
a.execute();
}
class LoadAllProduct extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(c);
pDialog.setMessage("Chargement Travail...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Product: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
products = json.getJSONArray(TAG_PRODUCTS);
Intent t=new Intent();
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
id = c.getString(TAG_PID);
this.name = c.getString(TAG_NAME);
/**
** i want to pass this.name in the Fragment1.java **
**/
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
productsList.add(map);
}
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
가
가/** * 백그라운드 작업이 대화 진행을 해제 완료 한 후 * **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
}
});
}
}
}
// 이것은이다 : 이 코드의 내 부분이다 클래스 프래그먼트
public class Fragment1.java extends Fragment {
}
나는 이미 ** 당신의 이전 질문에 답했습니다 ** 매우 비슷합니다 **. http://stackoverflow.com/a/24608867/2291104 주요 아이디어는 AsyncTask를 정적으로 만들고 생성자에 데이터를 전달하는 것입니다. –
신속한 답변에 감사드립니다 !! 나는 미안하다. 링크 주셔서 감사합니다! – user192417
MainChauffeur.java에서 사용할 때 static 클래스를 사용하지만 this.name 변수가 여전히 null입니다. – user192417