在我的應用程序中,我有一個listview,每個項目都有一個按鈕。如果用戶點擊按鈕,我想執行一些http連接。所以我在Adapter類中使用AsyncTask。現在問題是進展對話框沒有顯示。Android:ProgressDialog沒有顯示在Adapter類中
private class MyClass extends AsyncTask<Void, Long, Boolean> {
private Context context;
private ServerCall call = new ServerCall();
private ProgressDialog progressDialog1;
public MyClass(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
try {
progressDialog1 = ProgressDialog.show(context, "",
"Please wait...", true);
progressDialog1.setIndeterminate(true);
} catch (final Throwable th) {
}
}
@Override
protected void onProgressUpdate(Long... values) {
super.onProgressUpdate(values);
}
@Override
protected Boolean doInBackground(Void... params) {
//some tasks
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if (mode.equalsIgnoreCase("History")) {
Intent order = new Intent(context, ActicityA.class);
order.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(order);
} else {
Intent order = new Intent(context, ActivityB.class);
order.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(order);
}
}
}
被onPreExcute()調用的方法?我們需要mor信息。 –
@LazyNinja是onPreExcute()調用。我在lagcat中看到它 – Sridhar
爲什麼不在preExecute方法內的catch塊中記錄異常。如果你在那裏得到例外,你會知道問題是什麼。 – Sameer