这几天刚好在弄底部菜单,网上也有许多资料,其中我选择了一个
使用TabHost、radioGroup(http://www.apkbus.com/android-73873-1-1.html)的学习,在它的基础上我想进一步的扩展,首先我给一个页面加了一个listview,这个时候问题就出现了,再次运行项目时便会出现如下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wyj.tabmenu/com.wyj.tabmenu.TabMenu}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wyj.tabmenu/com.wyj.tabmenu.Home_Page}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
我在网上查了了些资料,主要说是个子view 已经有个父view了,你现在要使用的话,必须把子view从父view中移除掉,我自己虽然知道大概什么时候,但是自己本身也是半路出家搞Android的,都不知道如何解决,最后,在其他地方找到一个方法,在自定义的适配器的getview方法这样写:
public View getView(int position, View contentView, ViewGroup arg2) {
// TODO Auto-generated method stub
if(contentView==null)
{
contentView=LayoutInflater.from(getApplicationContext()).inflate(R.layout.myexam_item, null);
}
return contentView;
}
// TODO Auto-generated method stub
if(contentView==null)
{
contentView=LayoutInflater.from(getApplicationContext()).inflate(R.layout.myexam_item, null);
}
return contentView;
}
问题就可以解决了,今晚把它写出来主要留给加深自己的印象,同时希望可以帮到有需要的人。