我有一個問題,我的一些初始代碼移動到Asynctask中。Asynctask進度對話框
我一直在閱讀幾個Asynctask示例以及Asynctask上的Android開發人員文章,但是我發現很難將其與我能夠理解的代碼聯繫起來。
下面的代碼給我一個錯誤和執行doInBackground()時力關閉,是造成:了java.lang.RuntimeException:不能()內螺紋已不叫Looper.prepare創建處理程序
public class LoadingDialog extends AsyncTask<ArrayList<HashMap<String, String>>, Void, ArrayList<HashMap<String, String>>>
{
ProgressDialog pDialog = new ProgressDialog(Home.this);
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
pDialog = ProgressDialog.show(Home.this, "", "Loading...");
}
protected ArrayList<HashMap<String, String>> doInBackground(ArrayList<HashMap<String, String>>... params) {
// TODO Auto-generated method stub
finalList.clear();
eventList = database.getEvents();
venueList = database.getVenues();
finalList = createFinalList(eventList, venueList);
return finalList;
}
@Override
protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
// TODO Auto-generated method stub
pDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(Home.this, finalList , R.layout.home,
new String[] { "eventName", "venueName", "startTime"},
new int[] { R.id.item_title, R.id.item_subtitle, R.id.item_datetime });
setListAdapter(adapter);
lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent i = new Intent(Home.this, EventInfo.class);
HashMap<String, String> map = finalList.get(position);
String eID = map.get("eventId");
String name = map.get("eventName");
String venue = map.get("venueName");
String lati = map.get("venueLatitude");
String longi = map.get("venueLongitude");
String opening = map.get("openingTimes");
String descrip = map.get("venueDescription");
String vID = map.get("venueId");
String email = map.get("venueEmail");
String phone = map.get("venuePhone");
String facebook = map.get("venueFacebook");
String twitter = map.get("venueTwitter");
i.putExtra("itemId", eID);
i.putExtra("itemName", name);
i.putExtra("venueName", venue);
i.putExtra("venueLati", lati);
i.putExtra("venueLong", longi);
i.putExtra("opening", opening);
i.putExtra("venueDescription", descrip);
i.putExtra("venueID", vID);
i.putExtra("venueEmail", email);
i.putExtra("venuePhone", phone);
i.putExtra("venueFacebook", facebook);
i.putExtra("venueTwitter", twitter);
startActivityForResult(i, 0);
}
});
}
}
這是家庭類的一部分:
public class Home extends ListActivity {
int eventid;
String[] venue = null;
String[] name = null;
private SqlParser database = new SqlParser();
private ArrayList<HashMap<String, String>> eventList = new ArrayList<HashMap<String, String>>();
private ArrayList<HashMap<String, String>> venueList = new ArrayList<HashMap<String, String>>();
private ArrayList<HashMap<String, String>> finalList = new ArrayList<HashMap<String, String>>();
ListView lv = null;
我真的很感激任何幫助。
什麼'createFinalList'嗎?根據你的描述,錯誤來自那裏或從你的數據庫 – njzk2 2012-03-20 12:48:41