2011-07-21 41 views
0


我的應用程序使用HoneyComb片段,其中我的左側面板有listview,右側面板有一個MapView和一些TextViews.Initially我寫了map_fragment_right_side.xml中的地圖視圖,在冷凍長時間的屏幕上,所以決定在運行時膨脹地圖視圖中白白.The代碼的AsyncTask是這樣我怎樣才能從一個非UI胎面上充氣MapView

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); 
     } 






    } 

} 

我懷疑是否其可能從膨脹非UI線程地圖視圖。如果有人建議我以正確的方式做到這一點,我會很高興。我不希望屏幕凍結,直到地圖加載完畢。
感謝,
Ganesh神

回答

2

onPreExecute()它充氣或onPostExecute()

+0

尼古拉,就是再喜歡在UI線程執行。 – ganesh

+1

您無法從非ui線程觸發UI上的更新。 –

+0

是的,我同意你的看法尼古拉,我非常渴望找到HoneyComb中緩慢加載地圖視圖的解決方案。 – ganesh