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

时间:2015-06-25 17:53:27

标签: android tabs android-tabs

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

答案 0 :(得分:-1)

If I understood you correctly you want your current tabs replaced by new ones as soon as the user clicks on an object inside one of your tab fragments. In that case you could a) Create a new instance of your TabHost and fill it with your new tabs. b) Simply open another fragment on top of your current fragment that contains the TabHost and just change the arguments for filling the TabHost. I'd go with b) as it is more clean in my opinion at give your users the ability to go back and forth between your views without you having to handle the variables of the different TabHosts yourself.