Sri*_*har 5 android android-context android-adapter android-asynctask
在我的应用程序中,我有一个listview,每个项目都有一个按钮.如果用户单击该按钮,我想执行一些http连接.所以我在Adapter类中使用AsyncTask.现在问题是进度对话框没有显示.
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Shr*_*ant -1
该ProgressDialog.show()方法确实返回一个ProgressDialog对象,但最好首先创建一个 ProgressDialog 对象,如下所示:
ProgressDialog progressDialog1 = new ProgressDialog();
Run Code Online (Sandbox Code Playgroud)
进而
progressDialog1 = ProgressDialog.show(context, "",
"Please wait...", true);
Run Code Online (Sandbox Code Playgroud)
并且,尝试通过调用其方法来完成progressDialog1in 。onPostExecute()dismiss()
| 归档时间: |
|
| 查看次数: |
2751 次 |
| 最近记录: |