I set up ProgressDialog right after setContentView to pop ProgressDialog up.
After it's completed map image data on mapview, I wanna call method to dismiss ProgressDialog.
I wanna know where should I write the code to dismiss it.
I've written these source code as below. I'm so appreciated if you help me.
Thank you.
Here is my map activity class:
package sample.MyMap;
import sample.MyMap.R;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MyLocationOverlay;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class MyMapActivity extends MapActivity {
private MyMapView map;
private MapController controller;
private ProgressDialog progressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("TEST", this + " onCreate");
setContentView(R.layout.main);
progressDialog = ProgressDialog.show(this, "Please wait...", "Loading map view ...", true);
initMapView();
initMyLocation();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
private void initMapView() {
map = (MyMapView) findViewById(R.id.map);
controller = map.getController();
map.setSatellite(false);
map.setBuiltInZoomControls(true);
}
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.enableCompass();
overlay.runOnFirstFix(new Runnable() {
public void run() {
controller.setZoom(18);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
}
Here is my mapview class:
package sample.MyMap;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import com.google.android.maps.MapView;
public class MyMapView extends MapView {
public MyMapView(Context context, String apiKey) {
super(context, apiKey);
}
public MyMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Log.d("TEST", "onDetachedFromWindow");
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.d("TEST", "onSizeChanged");
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.d("TEST", "onWindowFocusChanged");
}
@Override
public void preLoad() {
super.preLoad();
Log.d("TEST", "preLoad");
}
}
Here is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="sample.MyMap">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name="MyMapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter&g开发者_如何学Got;
</activity>
<uses-library android:name="com.google.android.maps"></uses-library>
</application>
</manifest>
Put your initMapView & initMyLocation method in thraed as describe in below code & after this method dismiss the dialog as define below
new Thread(new Runnable()
{
public void run()
{
initMapView();
initMyLocation();
progressDialog.dismiss();
}
}).start();
精彩评论