使用RadioGroup切换tabhost的问题
2017-01-02 06:57
357 查看
我没有继承TabActivity
TabHost tabHost = (TabHost)this.findViewById(R.id.tabhost);
// 如果没有继承TabActivity时,通过该种方法加载启动tabHost
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Tab1"
).setContent(R.id.tab1));
tabHost.addTab(tabHost.newTabSpec("Tab2").setIndicator("Tab2")
.setContent(R.id.tab2));
tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("Tab3")
.setContent(R.id.tab3));
tabHost.addTab(tabHost.newTabSpec("Tab4").setIndicator("Tab4")
.setContent(R.id.tab4));
radioGroup1.setOnCheckedChangeListener(this);
然后用了个RadioGroup去切换
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch(arg1){
case R.id.radio0:tabHost.setCurrentTabByTag("Tab1");break;
case R.id.radio1:tabHost.setCurrentTabByTag("Tab2");break;
case R.id.radio2:tabHost.setCurrentTabByTag("Tab3");break;
case R.id.radio3:tabHost.setCurrentTabByTag("Tab4");break;
}
}
但是按下Radio总是出错
应该是tabHost.setCurrentTabByTag("");这句有问题,请大家指导下。。。
xml中命名
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10.5" >
TabHost tabHost = (TabHost)this.findViewById(R.id.tabhost);
// 如果没有继承TabActivity时,通过该种方法加载启动tabHost
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Tab1"
).setContent(R.id.tab1));
tabHost.addTab(tabHost.newTabSpec("Tab2").setIndicator("Tab2")
.setContent(R.id.tab2));
tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("Tab3")
.setContent(R.id.tab3));
tabHost.addTab(tabHost.newTabSpec("Tab4").setIndicator("Tab4")
.setContent(R.id.tab4));
radioGroup1.setOnCheckedChangeListener(this);
然后用了个RadioGroup去切换
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch(arg1){
case R.id.radio0:tabHost.setCurrentTabByTag("Tab1");break;
case R.id.radio1:tabHost.setCurrentTabByTag("Tab2");break;
case R.id.radio2:tabHost.setCurrentTabByTag("Tab3");break;
case R.id.radio3:tabHost.setCurrentTabByTag("Tab4");break;
}
}
但是按下Radio总是出错
应该是tabHost.setCurrentTabByTag("");这句有问题,请大家指导下。。。
xml中命名
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10.5" >
相关文章推荐
- 使用 RadioGroup+TabHost 搭建框架实现 导航 切换
- 使用RadioGroup做tab切换的变形问题
- 使用RadioGroup+ViewPager+Fragment实现带滑动的页卡效果TabHost时遇到的问题
- 关于RadioGroup切换数据和布局的一些小问题
- 使用radiogroup和viewpage实现底部导航出现的按钮选中界面没有改变的问题
- Android 使用ViewPager和RadioGroup配合Fragment实现标签页,可点击按钮切换、滑动切换。
- Android中使用RadioGroup实现Fragment的切换
- 如何使用RadioGroup和RadioButton实现FragmentTabHost导航效果?
- 使用RadioGroup 的时候出现onCheckChanged() 执行了三次的问题和App重启页面重叠现象
- 通过RadioGroup切换Fragment,快速切换会导致Fragment重叠或者IndexOutOfBoundsException: Invalid index 1, size is 1的问题
- 主界面的Fragment切换之使用RadioGroup配合切换Fragment
- RecyclerView嵌套使用RadioGroup出现的问题
- Viewpager结合RadioGroup切换的卡顿,不流畅问题
- 使用TabHost装载Activity, 当切换activity时,使activity刷新问题(执行oncreate()方法)
- 做了个底部菜单,精仿智联底部菜单栏,使用TabHost、radioGroup
- 妙用TabHost----TabHost+RadioGroup组合使用
- RadioGroup结合RadioButton使用切换Fragment片段
- RadioGroup 的使用
- Microsoft Office Word 2007 切换窗口后鼠标无法使用问题的解决办法
- Backup Exec 12在使用Recovery Storage Group进行恢复遇到的问题