使用clearAllTabs()这个方法删除tab的后,然后再添加 tab 就会抛 nullPointmentException下面的资料说是android 的bug http://code.google.com/p/android/issues/detail?id=2772调用这个 clearAllTabs()这个方法的前需要 调用 tabHost.setCurrentTab(0);tab的下标设置为0,但是这样的话每次更新tab里的内容都会显示第一个tab,这是不爽的地方。又查了一下资料http://www.coderanch.com/t/460859/Android/Mobile/TabHost-Remove-Tab里面谈到了另外一个方法,测试没通过还是抛 NullPointException 1. // data structure, what I referred to as memory
2. ArrayList<TabHost.TabSpec> list = new ArrayList<TabHost.TabSpec>();
3.
4. // when you are adding tabs to tab host
5. // what you add, you remember
6. TabHost.TabSpec spec = tabs.newTabSpec("tag1");
7. spec.setContent(R.id.button);
8. spec.setIndicator("TabONe");
9. tabs.addTab(spec);
10. list.add(spec);
11. ...
12. // when you want to remove
13. list.remove(list.size()-1); // remove it from memory
14. tabs.clearAllTabs(); // clear all tabs from the tabhost
15. for(TabHost.TabSpec spec : list) // add all that you remember back
16. tabs.addTab(spec); 哪位路过的大侠是否有好的解决方案,谢谢了
2. ArrayList<TabHost.TabSpec> list = new ArrayList<TabHost.TabSpec>();
3.
4. // when you are adding tabs to tab host
5. // what you add, you remember
6. TabHost.TabSpec spec = tabs.newTabSpec("tag1");
7. spec.setContent(R.id.button);
8. spec.setIndicator("TabONe");
9. tabs.addTab(spec);
10. list.add(spec);
11. ...
12. // when you want to remove
13. list.remove(list.size()-1); // remove it from memory
14. tabs.clearAllTabs(); // clear all tabs from the tabhost
15. for(TabHost.TabSpec spec : list) // add all that you remember back
16. tabs.addTab(spec); 哪位路过的大侠是否有好的解决方案,谢谢了
解决方案 »
- NDK编译出错,求救,希望高手帮忙
- Android EditView高度问题
- 请大神帮我看看这是什么错误。
- Android下SQLite数据库一条条地插入记录太慢了,1000条记录要30来秒时间,怎么改进?
- Sqlite insert不成功
- android 4.0 如何实现在没有activity情况下开机自启动服务,非常急。。。
- 新人概念求问,关于android与jquery mobil的关系
- 我的记事本之--登录注册功能实现
- 安卓GridView
- AndroidStudio混淆打包出错:proguard.ParseException: Unknown option 'public' in line 49
- 亲,怎么向服务器里面写文件?亲,100分哦!!!
- android开发中能直接调用系统里面自带的音乐和视频播放器吗?
currentPage = 0;
}/******************************/getCurrentTab()方法可以获得当前页的位置~删除前保留了就OK~然后再用setCurrentTab();