好像mapview不能直接用在TabActivity页面上,我想做一个分页程序,其中有一个分页用来存放地图,请问该怎么显示啊
public class MobileTrack extends TabActivity {
/** Called when the activity is first created. */
private MapView mapview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true);
//mapview=(MapView)findViewById(R.id.map);
/*TabSpec tab1;
tab1=tabHost.newTabSpec("tab1");
tab1.setIndicator("Location", getResources().getDrawable(R.drawable.location));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab1.setContent(R.id.scrollView2);
tabHost.addTab(tab1);
TabSpec tab1;
tab1=tabHost.newTabSpec("tab1");
tab1.setIndicator("Location", getResources().getDrawable(R.drawable.location));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab1.setContent(R.id.scrollView2);
tabHost.addTab(tab1);
*/
tabHost.addTab(tabHost.newTabSpec("Map").setIndicator("Map").setContent(new TabHost.TabContentFactory() { public View createTabContent(String arg0) { return mapview; } }));
TabSpec tab2;
tab2=tabHost.newTabSpec("tab2");
tab2.setIndicator("GPS", getResources().getDrawable(R.drawable.gps));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab2.setContent(R.id.scrollView2);
tabHost.addTab(tab2);
TabSpec tab3;
tab3=tabHost.newTabSpec("tab3");
tab3.setIndicator("Network", getResources().getDrawable(R.drawable.network));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab3.setContent(R.id.scrollView3);
tabHost.addTab(tab3);
TabSpec tab4;
tab4=tabHost.newTabSpec("tab4");
tab4.setIndicator("Hardware", getResources().getDrawable(R.drawable.hardware));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab4.setContent(R.id.scrollView4);
tabHost.addTab(tab4);
网上找了一些代码,总是不行,运行报错,求高手指点
public class MobileTrack extends TabActivity {
/** Called when the activity is first created. */
private MapView mapview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true);
//mapview=(MapView)findViewById(R.id.map);
/*TabSpec tab1;
tab1=tabHost.newTabSpec("tab1");
tab1.setIndicator("Location", getResources().getDrawable(R.drawable.location));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab1.setContent(R.id.scrollView2);
tabHost.addTab(tab1);
TabSpec tab1;
tab1=tabHost.newTabSpec("tab1");
tab1.setIndicator("Location", getResources().getDrawable(R.drawable.location));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab1.setContent(R.id.scrollView2);
tabHost.addTab(tab1);
*/
tabHost.addTab(tabHost.newTabSpec("Map").setIndicator("Map").setContent(new TabHost.TabContentFactory() { public View createTabContent(String arg0) { return mapview; } }));
TabSpec tab2;
tab2=tabHost.newTabSpec("tab2");
tab2.setIndicator("GPS", getResources().getDrawable(R.drawable.gps));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab2.setContent(R.id.scrollView2);
tabHost.addTab(tab2);
TabSpec tab3;
tab3=tabHost.newTabSpec("tab3");
tab3.setIndicator("Network", getResources().getDrawable(R.drawable.network));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab3.setContent(R.id.scrollView3);
tabHost.addTab(tab3);
TabSpec tab4;
tab4=tabHost.newTabSpec("tab4");
tab4.setIndicator("Hardware", getResources().getDrawable(R.drawable.hardware));
//Intent i1=new Intent(this.getApplicationContext(), ScrollView.class);
tab4.setContent(R.id.scrollView4);
tabHost.addTab(tab4);
网上找了一些代码,总是不行,运行报错,求高手指点
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货