我有一个 Overlay 扩展,它有 2 个对话框作为私有(private)属性 - 一个对话框和一个 ProgressDialog。单击 MapView 中的 Overlay 后,会出现 Dialog 对象。当用户单击对话框中的按钮时,它会消失并显示 ProgressDialog。同时通过通知正在运行的服务启动后台任务。任务完成后,将调用 Overlay 对象中的方法 (buildingLoaded) 来切换 View 并关闭 ProgressDialog。正在切换 View ,正在运行代码(我用调试器检查过)但 ProgressDialog 没有被关闭。我还尝试了 hide() 和 cancel() 方法,但没有任何效果。有人可以帮我吗? 安卓版本为2.2
代码如下:
public class LODOverlay extends Overlay implements OnClickListener {
private Dialog overlayDialog;
private ProgressDialog progressDialog;
..............
@Override
public void onClick(View view) {
.......
final Context ctx = view.getContext();
this.progressDialog = new ProgressDialog(ctx);
ListView lv = new ListView(ctx);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx, R.layout.layerlist, names);
lv.setAdapter(adapter);
final LODOverlay obj = this;
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String name = ((TextView) view).getText().toString();
Intent getFloorIntent = new Intent(Map.RENDERER);
getFloorIntent.putExtra("type", "onGetBuildingLayer");
getFloorIntent.putExtra("id", name);
view.getContext().sendBroadcast(getFloorIntent);
overlayDialog.dismiss();
obj.waitingForLayer = name;
progressDialog.show(ctx, "Loading...", "Wait!!!");
}
});
.......
}
public void buildingLoaded(String id) {
if (null != this.progressDialog) {
if (id.equals(this.waitingForLayer)) {
this.progressDialog.hide();
this.progressDialog.dismiss();
............
Map.flipper.showNext(); // changes the view
}
}
}
最佳答案
不确定这是否是您问题的原因,但您在 ProgressDialog
上调用的方法是 static
,但您是在类的实例上调用它.这是方法定义:
public static ProgressDialog show (Context context, CharSequence title, CharSequence message)
如您所见,该方法返回一个ProgressDialog
,它不会在您的类实例上执行show
操作。更新您的代码以使用其中之一:
progressDialog.setTitle("Loading...");
progressDialog.setMessage("Wait!!!");
progressDialog.show();
或
progressDialog = ProgressDialog.show(ctx, "Loading...", "Wait!!!");
关于android - ProgressDialog 在执行dismiss、hide 或cancel 后不消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4618730/