0
public SimpleAsyncTask(JSONObject obj, Activity activity) {
    this.obj = obj;
    this.activity = activity;
}

@Override
protected String doInBackground(String...params) {    
    String result = "";    
    return result;
}

@Override
protected void onPostExecute(String result) {
    List<Appointments> lists = new ArrayList<Appointments>();
    return lists;
}

@Override
protected void onPreExecute() {

}

我从 MainUI 线程调用我的 AsyncTask 线程。我有一个具有 listView 的片段类,我将如何通过List to my Fragment class.

ArrayAdapter < String > adapter = new ArrayAdapter < String > (getActivity(),
        android.R.layout.simple_list_item_1, listObject);
setListAdapter(adapter);
4

1 回答 1

1

只需使列表变量成为 Fragment 类的成员,而不是在 AsyncTask 范围内

像这样的东西:

public class MyFragment extends Fragment {

    private List<Appointments> lists = new ArrayList<Appointments>();
    ......

然后在您的 AsyncTask 中,按如下方式使用它:

    @Override
    protected void onPostExecute(String result) {
        // Not instantiating it from scratch, but using the class variable
        lists = new ArrayList<Appointments>();
        return lists;
     }
于 2013-03-31T13:02:25.883 回答