0

在我的活动中,我设计了一个导航抽屉,所以当我点击片段时,我的活动会像这样挂起:

我的活动 http://imageshack.com/scaled/large/844/z5ta.png

它冻结了 5~6 秒,所以我想显示一个纺车。我知道我应该扩展 AsyncTask 但它没有用!这是我尝试过的:

private void samsung{
    // TODO Auto-generated method stub
    Url = "/// ////////////// //////////// /////////////.php";
    new loadSomeStuff().execute(Url);
}

这是我的 aSyncTask 类:

public class loadSomeStuff extends AsyncTask<String, Integer, String> {
    ProgressDialog dialog;

    protected void onPreExecute(String f) {
        dialog = new ProgressDialog(Fragment9.this.getSherlockActivity());
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setCancelable(false);
        dialog.setIndeterminate(true);

        dialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        beanClass.clear();
        list.setAdapter(null);
        String result = "";
        InputStream isr = null;
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httpost = new HttpPost(Url);
            HttpResponse resposne = httpclient.execute(httpost);
            HttpEntity entity = resposne.getEntity();
            isr = entity.getContent();
        } catch (Exception e) {
            Log.e("log_httpconnection",
                    "error in http connection" + e.toString());
            Toast.makeText(getSherlockActivity(), "No Connection",
                    Toast.LENGTH_SHORT).show();
        }

        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(isr, "UTF-8"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            isr.close();
            result = sb.toString();
        } catch (Exception e) {
            Log.e("log_json", "Error converting Result " + e.toString());
        }
        try {
            JSONArray jArray = new JSONArray(result);
            for (int i = 0; i < jArray.length(); i++) {
                JSONObject json = jArray.getJSONObject(i);
                beanClass.add(new BeanClass(json.getString("PhoneName"),
                        json.getString("ModelNumber"), json
                                .getString("PhonePrice"), json
                                .getString("imageurl")));

            }
            dbHelpersamsung.deletesamsunglebanonphones();
            dbHelpersamsung.insertthephonessamsunglebanon();
        } catch (Exception e) {
            Log.e("lag_tag", "ERROR PARSING DATA" + e.toString());
            displaylistviewsamsunglebanon();
        }
        return null;
    }

    protected void onProgressUpdate(Integer... progress) {

    }

    protected void onPostExecute(String result) {
        list.setAdapter(new MyListAdapter(getActivity(), beanClass));

    }
}
4

1 回答 1

1

你有这个

  list.setAdapter(null);

和这个

     Toast.makeText(getSherlockActivity(), "No Connection",
                Toast.LENGTH_SHORT).show();

doInbackground无法更新 ui 。更新 uionPostExecute或者你runOnUiThread

于 2013-07-06T16:34:30.727 回答