0

I'm creating a map using the google api lib. Because the mapwidget takes a long time to load I'm trying to add a loading notification, but it isn't shown. I can show the progressDialog in regular threads though. How come this dialog isn't shown?

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        progressDialog = ProgressDialog.show(this, "Please Wait", "Map = loading",false,true);
        //setContentView(R.layout.map);
        runOnUiThread(new Runnable(){
            public void run() {
                try{
                    Log.d("debug", "before setContentView");                        //13:36:25
                    setContentView(R.layout.map);
                    Log.d("debug", "after setContentView");                         //13:36:39

                } catch (Exception e) { }

                progressDialog.dismiss();
            }});

        initMap();     
        initGps();

    }
4

2 に答える 2

1

It is pointless to put up a ProgressDialog for a MapActivity because "the mapwidget takes a long time to load", because you have no way to know when the MapView is done loading, so you have no way to know when to dismiss the dialog. setContentView() itself should run fairly quickly; the actual loading of the map tiles happens asynchronously.

Note that the time it takes to display a MapView is mostly dependent upon the Internet connection back to the Google Maps servers. In most cases, it does not take particularly long, certainly not long enough to warrant a ProgressDialog.

于 2011-03-30T12:47:38.580 に答える
0

Used this as a solution:

http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/

于 2011-04-19T15:46:30.560 に答える