标签导航问题

时间:2012-09-17 12:59:05

标签: android android-layout android-widget android-tabhost android-view

我正在使用TabHost在活动类中使用制表符。

TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
Test testObj = new Test(this);
spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2");
spec2.setContent(testObj);

每个视图都分配给实现TabFactory的视图。

public class Test implements TabContentFactory {
@Override
public View createTabContent(String arg0) {

    v = mInflater.inflate(R.layout.activity_tab1, null);

    /**
     * Add your code here for buttons/list etc
     * An object lookup for your Button: 
     */
    b = (Button)v.findViewById(R.id.button1);

    b.setOnClickListener(this);
    return v;
}
public void setListViewNames() {
   //create a custom list view
}
public void setDetailedView() {
   //opens another detailed view when user clicks on any item on the list
   //here i use ViewGroup to remove the first view created in setListViewNames()
}
}

单击按钮,将创建一个listView。单击任何项​​目将转到另一个listView。第一个listView被删除为:

ViewGroup viewGroup = (ViewGroup) v.getParent();
viewGroup.removeView(v);
View v1 = mInflater.inflate(R.layout.custom_fullpicture, null);
viewGroup.addView(v1);

但是当我转到第一个标签然后单击第二个标签时,会抛出以下错误。

E/AndroidRuntime(1668): at android.widget.TabHost$FactoryContentStrategy.tabClosed        
(TabHost.java:658)

如何在标签中有效导航?每次单击时都找不到重新加载标签视图的方法。

有什么想法吗?

提前致谢!

0 个答案:

没有答案
相关问题