Want to show a ProgressDialog while loading the MapView

3551
1
Jump to solution
09-12-2013 06:51 AM
LeonardSimonse
New Contributor
Here's the situation: my app loads 1 MapView. Loading this view will take some time, of course.
I want a ProgressDialog to be shown during this loading time.
The proper way to this is by using an AsyncTask.
However: creating a new MapView object inside of the doInBackground method is not allowed: it's not allowed to interact with the UI inside this method.

Does anyone have a suggestion? Is there a way to do this? Could not find this through Google nor on this forum.
0 Kudos
1 Solution

Accepted Solutions
JasonKnisley
Occasional Contributor
One option is to include a Layout with a ProgressBar that is already visible when the map is launched, and then set an OnStatusChangedListener on the MapView to hide that Layout when the map is initialized.

mapView.setOnStatusChangedListener(new OnStatusChangedListener() {  public void onStatusChanged(Object sender, STATUS status) {   if (status.equals(STATUS.INITIALIZED)) {    findViewById(R.id.relativeLayoutLoading).setVisibility(View.GONE);   }  } });


On a side note, while I haven't actually tried it, I think you should be able to manipulate the MapView from a background thread by using runOnUiThread().
MyActivity.this.runOnUiThread(new Runnable() {  public void run() {   // do something  } });

View solution in original post

0 Kudos
1 Reply
JasonKnisley
Occasional Contributor
One option is to include a Layout with a ProgressBar that is already visible when the map is launched, and then set an OnStatusChangedListener on the MapView to hide that Layout when the map is initialized.

mapView.setOnStatusChangedListener(new OnStatusChangedListener() {  public void onStatusChanged(Object sender, STATUS status) {   if (status.equals(STATUS.INITIALIZED)) {    findViewById(R.id.relativeLayoutLoading).setVisibility(View.GONE);   }  } });


On a side note, while I haven't actually tried it, I think you should be able to manipulate the MapView from a background thread by using runOnUiThread().
MyActivity.this.runOnUiThread(new Runnable() {  public void run() {   // do something  } });

View solution in original post

0 Kudos