我有一个程序可以搜索一些元素并在 GoogleMap 上显示这些元素。我想在所有在地图上设置各种地理点的程序结束之前显示一个进度对话框。
搜索我发现此代码在方法结束之前显示进度对话框。
ProgressDialog dialog;
private class Test extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(Main.this);
dialog.setMessage("Loading....");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
}
@Override
protected Void doInBackground(Void... voids) {
try {
runOnUiThread(new Runnable() {
public void run() {
}
});
//your code
}
@Override
protected void onPostExecute(Void params) {
dialog.dismiss();
//result
}
}
我必须添加异步任务的类是这样的:
public class FindItOnMap extends MapActivity{
static String[] foundResults;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ricerca_condominio);
mapView = (MapView)findViewById(R.id.mapView);
mapController = mapView.getController();
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapController.setZoom(12);
myLocationOverlay = new MyLocationOverlay(this, mapView);
List<Overlay> overlays = mapView.getOverlays();
overlays.add(myLocationOverlay);
myLocationOverlay.enableMyLocation();
...........
((ImageButton) findViewById(R.id.btSearch)).setOnClickListener(mSearchListenerListener);
}
OnClickListener mSearchListener = new OnClickListener() {
public void onClick(View v) {
String Location=editorLocation.getText().toString();
String name=editorName.getText().toString();
//static method that updates the lists foundResult
search(name, location);
//static method that use the static array foundResult to update the map
updateMapWithResult();
}
};
当我点击一个按钮时,在返回解决方案之前需要时间的方法被调用
search(name, location);
updateMapWithResult();
问题是我的类扩展了 MapActivity,我不能使用多重继承来扩展另一个类。我该怎么做才能解决问题?