I read at another forum that someone else had this problem, he said he resolved it, but he didn’t post the solution. My R.Java doesn’t seem to be updating with the id’s in the nested LinearLayouts. The first two id’s in the textViews do appear in the R.Java (textView1 and textView2), but none of the subsequent id’s for the ImageButtons do…and I suspect it’s because of the layout (but being a noobie I have no idea why).
The layout as I have it is almost perfect, so I’d hate to rewrite it if I can avoid it. But I don’t know how to get the R.java to include the ID’s. And I’ve tried the usual build clean, refresh, etc. Any help would be greatly appreciated by me and my computer…because if I can’t figure this out soon, I’ll probably end up throwing it out the window in frustration. 🙂
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="86dp" android:background="@drawable/backgdtest" android:text=" Title of App" android:textColor="#ffffff" android:textSize="30px" android:textStyle="bold"/>
<TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:text=" " android:layout_height="wrap_content"></TextView>
<TableRow android:layout_width="fill_parent" android:weightSum="3" android:layout_height="wrap_content">
<LinearLayout android:layout_weight="1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/news" android:src="@drawable/news" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageButton>
<TextView android:layout_width="wrap_content" android:text=" Read News" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<LinearLayout android:layout_weight="1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/messages" android:src="@drawable/message" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageButton>
<TextView android:layout_width="wrap_content" android:text=" Messages" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<LinearLayout android:layout_weight="1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/phonebook" android:src="@drawable/phonebook" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageButton>
<TextView android:layout_width="wrap_content" android:text=" Phone Book" android:layout_height="wrap_content"></TextView>
</LinearLayout>
</TableRow>
<TableRow android:layout_width="fill_parent" android:weightSum="3" android:layout_height="wrap_content">
<LinearLayout android:layout_weight="1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/planner" android:src="@drawable/planner" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageButton>
<TextView android:layout_width="wrap_content" android:text=" Day Planner" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<LinearLayout android:layout_weight="1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/help" android:src="@drawable/panic" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageButton>
<TextView android:layout_width="wrap_content" android:text=" Call For Help" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<LinearLayout android:layout_weight="1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/exit" android:src="@drawable/exit" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageButton>
<TextView android:layout_width="wrap_content" android:text=" Exit Program" android:layout_height="wrap_content"></TextView>
</LinearLayout>
</TableRow>
There is no problem (in general) with nested layouts and ID generation. You are however, missing an end tag for the outer-most
TableLayout. Add a</TableLayout>to the end of your layout. Android won’t regenerate the R file if there are errors in a layout file – this is why you aren’t seeing the new IDs.If you are using the XML editor in Eclipse you will notice a red ‘x’ icon and the error message: ‘XML document structures must start and end within the same entity.’ You would also be able to see this error if you went to the ‘Problems’ view (
Window -> Show View -> Problems).