0

试图从异步任务填充列表视图...一切正常,我得到我的 json 响应,构建地图,但不知何故没有任何东西传递给 onPostExecute 并且在对话框被关闭后列表视图仍然为空...不要得到任何错误...有人有提示吗?

继承人的代码:

import org.apache.http.impl.cookie.BasicClientCookie;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.view.Menu;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONArray;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import com.loopj.android.http.*;

public class Success extends ListActivity {

private static final String TAG_TITLE = "title";
ProgressDialog mProgressDialog;
JSONArray data = null;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_success);
    new processHomeStream().execute();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.success, menu);
    return true;
}

class processHomeStream extends AsyncTask<ArrayList<HashMap<String, String>>, Void, ArrayList<HashMap<String, String>>>{

    @Override
    protected void onPreExecute(){
        super.onPreExecute();
        mProgressDialog = new ProgressDialog(Success.this);
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }

    @Override
    public ArrayList<HashMap<String, String>> doInBackground(ArrayList<HashMap<String, String>>... passing) {
        ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();

        final AsyncHttpClient client = new AsyncHttpClient();
        client.get("url-to-my-api", new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String response) { 

        try {
            ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();
            JSONObject json = new JSONObject(response);
            data = json.getJSONArray(TAG_ARRAY);
            for(int i = 0; i < data.length(); i++){
                // processing the son response
                }

                map.put(TAG_TITLE, title);
                result.add(map);                    
            }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                }
            }

        });

        return result;

    }

    @Override
    protected void onPostExecute(ArrayList<HashMap<String, String>> result){
        super.onPostExecute(result);
        mProgressDialog.dismiss();
        System.out.println(result);
        final ListAdapter adapter = new SimpleAdapter(Success.this, result, R.layout.list_item,
                new String[] { TAG_TITLE},
                new int[] { R.id.title,});

        setListAdapter(adapter);
        }


    }

}

谢谢!

4

0 回答 0