2015-06-25 153 views
-1

我需要在另一個選項卡內做一個選項卡,當我觸摸一個選項卡時,Android需要打開一組新的選項卡。誰能幫我?如何在Android的另一個選項卡內創建一個選項卡?

我使用這種代碼:它只適用於第一組選項卡。

th = (FragmentTabHost) findViewById(android.R.id.tabhost); 
th.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); 

//coloca o formulario dentro da tab 
th.addTab(
     th.newTabSpec("formulario 1").setIndicator("Aba 1", null), 
     FragmentTab.class, null); 
th.addTab(
     th.newTabSpec("formulario 2").setIndicator("Aba 2", null), 
     FragmentTab.class, null); 
th.addTab(
     th.newTabSpec("formulario 3").setIndicator("Aba 3", null), 
     FragmentTab.class, null); 
th.addTab(
     th.newTabSpec("formulario 4").setIndicator("Aba 4", null), 
     FragmentTab.class, null); 
th.addTab(
     th.newTabSpec("formulario 5").setIndicator("Aba 5", null), 
     FragmentTab.class, null); 
th.addTab(
     th.newTabSpec("formulario 6").setIndicator("Aba 6", null), 
     FragmentTab.class, null); 
th.addTab(
     th.newTabSpec("formulario 7").setIndicator("Aba 7", null), 
     FragmentTab.class, null); 

}

@Override 

公共查看onCreateView(LayoutInflater吹氣,ViewGroup中容器, 捆綁savedInstanceState){

View v = inflater.inflate(R.layout.fragment_layout, container, false); 
TextView tv = (TextView) v.findViewById(R.id.text); 

//pega a tag e compara com a string para inflar o xml 
if (this.getTag() == "formulario 2") { 
    return inflater.inflate(R.layout.activity_json, container, false); 
} 
if(this.getTag() == "formulario 3"){ 
    return inflater.inflate(R.layout.formulario3, container, false); 
} 
if(this.getTag() == "formulario 4"){ 
    return inflater.inflate(R.layout.formulario2, container, false); 
} 
else return v; 

} }

+2

請添加您正在使用的代碼和一點點更具體的瞭解你都要得到更好的幫助 –

+1

這真的不是很好的用戶界面設計問題。的 – 323go

+0

可能重複[嵌套片段選項卡上的Android重疊(http://stackoverflow.com/questions/26339241/nested-fragment-tabs-overlap-on-android) – 323go

回答

-1

如果我正確你瞭解你希望您的當前標籤repl只要用戶點擊一個標籤片段中的某個對象,就會被新的標籤添加。在這種情況下,你可以

一)創建TabHost的新實例,並用新的標籤填充它。

B)只需打開包含TabHost,只是改變參數來填充TabHost你的當前片段的頂部的另一個片段。

我會用b去),因爲它是我的看法更乾淨,讓使用者去來回您的觀點之間,您無需處理不同TabHosts自己的變量的能力。

相關問題