AsyncTask的onPreExecute和onPostExecute将在UI线程中运行,doInBackground将在另一个线程中运行,因此下面的代码对您来说很合适
public class YourActivity extends Activiy{ public void getJson(String selection, String url) { new LoadJsonTask().execute( selection, url); } private class LoadJsonTask extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > { ProgressDialog dialog ; protected void onPreExecute (){ dialog = ProgressDialog.show(YourActivity.this ,"title","message"); } protected ArrayList<HashMap<String, String>> doInBackground (String... params){return doGetJson(params[0],params[1]); } protected void onPostExecute(ArrayList<HashMap<String, String>> mylist){ ListAdapter adapter = new JsonAdapter(YourActivity.this, mylist, R.layout.list, new String[] { "name", "text", "ts"}, new int[] { R.id.item_title, R.id.item_subtitle, R.id.timestamp}); setListAdapter(adapter); dialog.dismiss(); } } public ArrayList<HashMap<String, String>> doGetJson(String selection, String url) { JSonObject json = null; String formatedcat = selection.toLowerCase(); ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); json = JSonfunctions .getJSonfromURL(url); try { //the array title that you parse JSonArray category = json.getJSonArray(formatedcat); for (int i = 0; i < category.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); JSonObject c = category.getJSonObject(i); map.put("id", String.valueOf(i)); map.put("name", c.getString("title")); //map.put("text",c.getString("title")); map.put("ts",c.getString("run_date") ); map.put("image","http:"+c.getString("url")); mylist.add(map); }} catch (JSonException e) {} return mylist; .... }


