2013-04-16 139 views
2

我有一个viewPager与一些页面:其中之一是一个WebView(下面的代码中的'情况0')。问题在于,代替地图显示地图,显示空白页面。我的实施有什么问题?MapView里面viewpager

编辑:清除代码

我的代码

@Override 
public Object instantiateItem(View container, int position) { 
    Context context = container.getContext(); 
    prepareViews(); 

    m_mapView = new MapView(context, null); 
    m_mapView.setBuiltInZoomControls(true); 
    m_mapView.setMultiTouchControls(false); 
    mapController = this.m_mapView.getController(); 



    LinearLayout layout = new LinearLayout(context); 
    switch (position) { 
    case 0: 
     layout.addView(m_mapView); 

     break; 
    case 1: 
     ... 
     break; 
    case 2: 
     ... 
     break; 
    } 
    ((ViewPager) container).addView(layout, 0); 
    return layout; 
} 
+0

你有什么解决方案吗? – anonymous

回答

0

在教程ViewPager的,它已被充气的布局。

public Object instantiateItem(View collection, int position) { 
    LayoutInflater inflater = (LayoutInflater) collection.getContext() 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    int resId = 0; 
    resId = profileLayouts[position]; 
    View view = inflater.inflate(resId, null); 

就你而言,你可以用layout变量来做到这一点。一旦它膨胀,你可以操纵它,添加地图,然后添加视图。

((ViewPager) collection).addView(view, 0); 
    return view; 
相关问题