首页 文章

如何在Android中的另一个标签内创建标签?

提问于
浏览
-1

我需要在另一个标签内做一个标签,当我触摸一个标签时,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

public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle 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;

}}

1 回答

  • -1

    如果我理解正确,那么只要用户点击其中一个标签片段内的对象,您就会希望当前标签被新标签替换 . 在那种情况下你可以

    a)创建TabHost的新实例并使用新选项卡填充它 .

    b)只需打开包含TabHost的当前片段顶部的另一个片段,然后更改填充TabHost的参数 .

    我会选择b)因为在我看来它更干净,让你的用户能够在你的视图之间来回切换,而不必自己处理不同TabHosts的变量 .

相关问题