W mojej aplikacji mam widok listy, a każdy element ma przycisk. Jeśli użytkownik kliknie przycisk, chcę wykonać pewne połączenie http. Używam AsyncTask w klasie Adapter. Problem polega na tym, że okno dialogowe postępu nie jest wyświetlane.Android: ProgressDialog nie jest wyświetlany w klasie adaptera
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);
}
}
}
została onPreExcute() metoda nazywa? Potrzebujemy więcej informacji. –
@LazyNinja yes onPreExcute() wywołana. widzę to w lagcat – Sridhar
Dlaczego nie logujesz wyjątku w bloku catch wewnątrz metody preExecute. Jeśli dostaniesz tam wyjątek, będziesz wiedział, jaki jest problem. – Sameer