解决android安卓TabHost默认进入第一个选项卡onCreate的问题.顺序问题
2012-10-18 11:24
615 查看
th = this.getTabHost(); int tadid = 2; // 设置mCurrentTab为非-1,addtab时候不会进入setCurrentTab() try { Field idcurrent = th.getClass().getDeclaredField("mCurrentTab"); idcurrent.setAccessible(true); idcurrent.setInt(th, -2); } catch (Exception e) { e.printStackTrace(); } th.addTab(th.newTabSpec("myview1").setIndicator("myview111").setContent(new Intent(this, MyView1.class))); th.addTab(th.newTabSpec("myview2").setIndicator("myview222").setContent(new Intent(this, MyView2.class))); th.addTab(th.newTabSpec("myview3").setIndicator("myview333").setContent(new Intent(this, MyView3.class))); // 设置mCurrentTab与tadid不同,并且不能数组越界(0-2),保证第一次进入tab的setCurrentTab()方法正常运行 try { Field idcurrent = th.getClass().getDeclaredField("mCurrentTab"); idcurrent.setAccessible(true); if (tadid == 0) { idcurrent.setInt(th, 1); } else { idcurrent.setInt(th, 0); } } catch (Exception e) { e.printStackTrace(); } th.setCurrentTab(tadid);
在我们使用TabHost 的时候,如果我们希望默认进入非第一个选项卡的时候,我们会这样写:tabHost.setCurrentTab(???);,但是,这样就出现了一个问题。我们发现无论进入哪个选项卡,在第一次进入TabHost的时候,都会调用第一个选项卡的 OnCreate方法! 这个不是我们想要的。 加上上面两个写注释的方法,即可解决问题!
相关文章推荐
- Android TabHost设置setCurrentTab(index),当index!=0时,默认加载第一个tab问题解决方法。
- Android TabHost取消默认加载第一个tab的问题
- android 解决进入activity 弹出输入对话框的问题
- 安卓:调用真正系统默认短信应用发短信. (含解决4.4系统环聊问题, 含调低版本apk调用高版本系统api)
- EasyRTMP Android安卓手机直播推流摄像头偏暗的问题解决
- Android TabHost设置默认选项卡
- Android 如何解决默认壁纸更改为ImageWallpaper之外的壁纸,在特定的操作下,导致死机的问题。
- 解决android程序中oncreate方法中调用百度地图MKSearchListener接口不执行的问题
- 解决安卓manifest中的application标签中@android:style/Theme.NoTitleBar崩溃的问题
- Android中如何修改tabhost的默认打开的tab选项卡
- 关于Android app首次安装完成后在安装界面直接“打开”应用再按home键返回桌面,重新进入app重复实例化launcher activity的问题的解决
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- android app从登录界面进入主页,按home键回桌面再进入app,重新弹出登录界面的问题解决
- EasyRTMP Android安卓手机直播推流摄像头偏暗的问题解决
- android在activity中锁屏解锁后重走OnCreate的问题的解决办法
- 关于Android app首次安装完成后在安装界面直接“打开”应用再按home键返回桌面,重新进入app重复实例化launcher activity的问题的解决
- 解决Android开发中ViewPager动态设置PagerAdapter时第二次进入Fragment内容不显示的问题
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- android监听软键盘回车键并且解决默认点击两次的问题