Issue
My app uses HoneyComb fragments where my left side panel has listview and right side panel has a MapView with some TextViews.Initially i wrote map view in the map_fragment_right_side.xml which resulted in freezing the screen for long time ,so I decided to inflate the map view at runtime in an AsyncTask in vain .The code goes like this
class LoadMapTask extends AsyncTask<String, Void, Boolean>
{
MapView inflatedMapView = null;
@Override
protected void onPreExecute() {
progressbar.setVisibility( View.VISIBLE );
}
@Override
protected Boolean doInBackground(String... params)
{
try{
inflatedMapView = new MapView(getActivity(),getActivity().getResources().getString(R.string.mapkey));
addMapViewhere.addView(inflatedMapView);
inflatedMapView.getController().setCenter(getPoint(Double.valueOf(latitude),Double.valueOf(longitude)));
inflatedMapView.getController().setZoom(17);
inflatedMapView.setBuiltInZoomControls(true);
sites=new SitesOverlay();
inflatedMapView.getOverlays().clear();
inflatedMapView.getOverlays().add(sites);
}catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
protected void onPostExecute(Boolean res)
{
if( progressbar != null )
{
progressbar.setVisibility( View.GONE );
}
}
}
I doubt whether its possible to inflate map view from non-UI thread .I will be glad if someone suggest me the right way to do this.I don't want the screen to freeze until map gets loaded.
thanks,
ganesh
Solution
Inflate it from onPreExecute()
or in onPostExecute()
Answered By - Nikola Despotoski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.