错误/ AndroidRuntime(10985):引起:java.lang.IllegalStateException:指定的孩子已经有父母。您必须先调用孩子的父母上的removeView() 。Android选项卡指定的子项已具有父项。您必须先调用孩子父母上的removeView()
这是我的XML tabs_dettaglio.xml
我使用的可视化标签:
Codice(XML):Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/relativeimg"
>
<RelativeLayout
android:id="@+id/relativeimg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:id="@+id/imageView3"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip">
</ImageView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeimg2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView2"
android:layout_marginLeft="220dip">
</ImageView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeimg3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView1"
android:layout_marginLeft="97dip">
</ImageView>
</RelativeLayout>
</RelativeLayout>
这是java代码:
private void setTabs() {
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("1").setContent(new Intent(this,d.class)).setIndicator(addImg(1)));
tabHost.addTab(tabHost.newTabSpec("2").setContent(new Intent(this,d.class)).setIndicator(addImg(2)));
tabHost.addTab(tabHost.newTabSpec("3").setContent(new Intent(this,d.class)).setIndicator(addImg(3)));
}
private View addImg(int i) {
int cc;
int cc2;
if(i==1) {
cc = R.id.imageView3;
cc2 = R.drawable.menu_oggi;
} else if(i==2){
cc = R.id.imageView2;
cc2 = R.drawable.menu_ieri;
} else {
cc = R.id.imageView1;
cc2 = R.drawable.menu_domani;
}
View tabIndicator = LayoutInflater.from(getBaseContext()).inflate(R.layout.tabs_dettaglio,null);
ImageView icon = (ImageView) tabIndicator.findViewById(cc);
icon.setBackgroundResource(cc2);
return icon;
}
安置自己的完整的错误日志,并告诉我们这行中出现的异常(如MyCode.java:34是线MyCode.java 34) – kcoppock 2011-05-15 00:10:28