我有一个覆盖扩展,它有 2 个作为私有属性的对话框 - 一个对话框和一个 ProgressDialog。单击 MapView 中的 Overlay 后,将出现 Dialog 对象。当用户单击对话框中的按钮时,它会消失并显示 ProgressDialog。同时通过通知正在运行的服务启动后台任务。任务完成后,调用 Overlay 对象中的方法(buildingLoaded)来切换 View 并关闭 ProgressDialog。视图正在切换,代码正在运行(我用调试器检查过),但 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
}
}
}
}