2012-01-05 33 views
0

我在活動中有2個選項卡,並且我想添加一個新選項卡並添加一個Google地圖,所以我需要創建一個擴展了mapactivity的活動。到現在爲止還挺好。 但我不知道如何選擇標籤才能顯示地圖。調用另一個不同活動的活動中的選項卡

這是我的代碼

TabHost tabhost =(TabHost)findViewById(R.id.tabHost); tabhost.setup();

TabSpec spec1 = tabhost.newTabSpec("tab1"); 
    spec1.setContent(R.id.tab1); 

    TabSpec spec2 = tabhost.newTabSpec("tab2"); 
    spec2.setContent(R.id.tab2); 

    TabSpec spec3 = tabhost.newTabSpec("map"); 
    spec3.setContent(R.id.tab3); 

    tabhost.addTab(spec1); 
    tabhost.addTab(spec2); 
    tabhost.addTab(spec3); 

標籤1和片2正在作爲碼是所有在相同的活性。

有幫助嗎?

回答

0
tabSpec=tabHost.newTabSpec("tab1"); 
    tabSpec.setIndicator("CLASS A"); 
    Intent i=new Intent(this,ClassA.class); 
    tabSpec.setContent(i); 
    tabHost.addTab(tabSpec); 

    tabSpec=tabHost.newTabSpec("tab2"); 
    tabSpec.setIndicator("CLASS B"); 
    Intent i=new Intent(this,ClassB.class); 
    tabSpec.setContent(i); 
    tabHost.addTab(tabSpec); 
0

您應該Fragments而不是Activities工作,以實現這一目標。 對於蜂窩前設備,有一個兼容性API可以使用Fragments

隨着Fragments你可以使用FragmentTransation切換到谷歌地圖在相同的Tab

+0

我正在使用蜂窩。那是問題嗎?你能給我一個示例代碼嗎?我是否必須更改所有的代碼,因爲它已經接近準備好了。我只需要添加此標籤與谷歌地圖。 – Adnama 2012-01-05 10:28:05

+0

如果您使用的是蜂巢,您可以使用碎片。 我認爲如果你正在開發蜂窩或更高版本,你應該使用片段。 [這裏](http://developer.android.com/guide/topics/fundamentals/fragments.html)是開始使用片段的一些信息。 – 2012-01-05 11:02:27

1

我聽說過MapViewMapFragment,但我不確定MapActivity的意思 - 可能是有人給你的自定義活動。但無論如何,我建議你創建一個MapView或MapFragment,並在用戶點擊應用程序中的Map-Tab時返回。您不必觸發其他活動即可顯示地圖屏幕。使用spec3.setContent(MapViewInstance)spec3.setContent(MapFragmentInstance)來實現你所需要的。 HTH。

相關問題