0

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>
        </activity>
        <uses-library android:name="com.google.android.maps"></uses-library>

    </application>
</manifest>
Atsushi
  • 1
  • 2

1 Answers1

1

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();
Mohit Kanada
  • 15,274
  • 8
  • 31
  • 41
  • Thank you for the advice. I tried the sauce which you taught. However, the result became the following run-time error. " java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()" Then, I changed the code so that the handler might be used. But it could not work well. According to the log file, the progress dialog was showed and dismissed immediately. I couldn't see the dialog on a screen. The Mapview had not completed downloading map's images. Could you tell me another ideas? – Atsushi Sep 12 '11 at 02:31
  • Try Like This:----- First make your progress dialog to static. After that try to put progressDialog.dismiss() in initMyLocation() method after map.getOverlays().add(overlay); Reply what you get... – Mohit Kanada Sep 12 '11 at 06:44
  • I tried just like your advice. But I got the same result as before. The dialog was dismissed soon. Then the mapview was still loading images. – Atsushi Sep 15 '11 at 14:22