I have a program that search some elements and show these on a GoogleMap.
I want to show a progress dialog before the end of all procedures that set the various geopoint on the map.
Searching I have found this code to show the progress dialog before the end of a method.
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
}
}
The class where I must add the async task is something like this:
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();
}
};
The methods that requires time before return the solution are invoked when I click on a button
search(name, location);
updateMapWithResult();
The problem is that my class extends yet MapActivity and I cannot use multiple inheritance to extend another class.
How could I do to solve the problem?
If you don’t want to use multiple inheritance, you can define your
AsyncTaskas an inner class and use an instantiated object of theAsycTaskyou defined to do your job. Something like this: