我有一个浮层扩展,其中有两个私有属性对话框——Dialog和ProgressDialog。在MapView中单击Overlay后,出现Dialog对象。当用户点击对话框中的按钮时,对话框消失并显示ProgressDialog。同时,通过通知正在运行的服务启动后台任务。当任务完成时,在Overlay对象中调用方法(buildingLoaded)以切换视图并关闭ProgressDialog。视图已经切换,代码已经运行(我用调试器检查过),但ProgressDialog没有被关闭。我还尝试了hide()和cancel()方法,但都无效。有人能帮帮我吗?
Android版本是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
}
}
}
}