0
 public class GetAllEggs extends AsyncTask<Void, Void, List<Egg>>  {
    List<Egg> eggs;
    Egg eg;
     JSONParser jParser = new JSONParser();
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }
    @Override
    protected List<Egg> doInBackground(Void... params) {
        // TODO Auto-generated method stub

        try {
            // Thread.sleep(5000);
            /*** fetch data from server and save in the local db ***/
            String url = Utils.alleggsofuser;
            JSONObject jObject  = jParser.makeHttpRequest(url, "GET", null);
            //Log.d(DEBUG_TAG, "news response: " + response);


            JSONArray categoryArray = new JSONArray(
                    jObject.getString("categories"));






            for (int i = 0; i < categoryArray.length(); i++) {
                /* make entries in the db */
                JSONObject Category = categoryArray.getJSONObject(i);
                eg=new Egg();
                    eg.setEggid(Category.getInt("eggid"));

                    eg.setApp_user_id(Category.getInt("app_user_id"));

                    eg.setEgg_query(Category.getString("egg_query"));
                    eg.setEgg_date_time(null);
                    eggs.add(eg);
                /**/
            }

            /**/
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            // pBar.cancel();
        }
        return eggs;
    }

    protected void onPostExecute(List<Egg> result) {
        // TODO Auto-generated method stub


    }


List<Egg> eggs=new ArrayList();  
new GetAllEggs().execute(eggs);

我希望鸡蛋获取返回的数据GetAllEggs().execute()

这样我就可以在另一个可以显示的类中使用返回的鸡蛋。

我正在尝试将返回的数据分配给新类中的列表。

postexecute()由于程序的结构,我无法执行操作

4

1 回答 1

0

我可以使用 runOnUiThread(new Runnable() { public void run() {}}) 在 post execute 中调用 ui 线程,而不是从 post execute 传递到 ui 线程;

于 2013-05-10T06:02:37.790 回答