2015-06-25 154 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自己的变量的能力。

相关问题