Search code examples
androidxmllayoutr.java-file

not add id component in R.java file


I have encountered the same problem - when I want to add to the id LinearLayout in XML file, Eclipse says that the file is built correctly - but for the component ID is not available - it is not added to the file R.java. Perhaps this is due to the fact that for a given component is specified warning "This LinearLayout layout or its TableRow parent is possibly useless"? How can I solve this problem? I hope for your help.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="#E8E8E8" >

<TableLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content">


    <TableRow 
        android:id="@+id/base_table_row1"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:paddingTop = "15dp"
        android:paddingBottom = "15dp"
        android:gravity = "center"> 

        <TextView
        android:id="@+id/name_placeView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="name of the place"
        android:gravity="center"
        android:textStyle="bold"            
        android:textColor="#000000"
        android:textSize="30sp"/>
        </TableRow>

    <TableRow 
        android:id = "@+id/base_table_row3"
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"          
        android:gravity = "center"> 

        <TextView
            android:id="@+id/info_placeView"
            android:textColor="#808080"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text="adress"/>
    </TableRow>

     <TableRow 
        android:id = "@+id/base_table_row2"
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"
        android:paddingBottom = "15dp"
        android:gravity = "center"> 

        <TextView
            android:id="@+id/info_placeView"
            android:layout_width="wrap_content"
            android:textColor="#808080"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:layout_height="wrap_content"
            android:text="There will be placed an short information about place"/>

     </TableRow> 

     <TableRow 
        android:id = "@+id/base_table_row3"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:paddingTop = "15dp"
        android:gravity = "center"> 

        <TextView
            android:id="@+id/comfortView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:textColor="#DAA520"
            android:text="Atmosphear"/>
    </TableRow>


    <TableRow 
        android:id = "@+id/base_table_row4"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:gravity = "center"> 

        <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
             android:orientation = "vertical"
             android:layout_width = "wrap_content"
             android:layout_height = "wrap_content"
             android:gravity="center">  

            <RatingBar
                android:id="@+id/ratingBar1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:numStars="5"
                android:stepSize="1.0" />

        </LinearLayout>

   </TableRow>


   <TableRow 
        android:id = "@+id/base_table_row5"
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"
        android:paddingTop = "15dp"
        android:gravity = "center">

        <TextView
            android:id="@+id/priceView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:textColor="#DAA520"
            android:text="Peoplemeter" />

   </TableRow>


    <TableRow 
        android:id = "@+id/base_table_row6"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:gravity = "center"> 

        <LinearLayout
             xmlns:android = "http://schemas.android.com/apk/res/android"
             android:id="@+id/layout_rate_bar2"
             android:orientation = "vertical"
             android:layout_width = "wrap_content"
             android:layout_height = "wrap_content"
             android:gravity="center"> 

            <RatingBar             
                 android:numStars="5"
                 android:id="@+id/ratingBar2"
                 android:stepSize="1.0"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"/>

        </LinearLayout>

    </TableRow>             

    <TableRow 
        android:id = "@+id/base_table_row7"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:paddingTop = "20dp"         
        android:gravity = "center"
        > 

         <LinearLayout
            android:id = "@+id/final_rate_layout"
            android:orientation = "vertical"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:gravity="center"
            > 

            <Button
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content" 
                    android:background="@drawable/button_custom_rate"
                    android:textStyle="bold"
                    android:textSize="20sp"                             
                    android:text="RATE IT"
                    android:id="@+id/final_rate"
                    android:clickable="true"
                    />

        </LinearLayout>         

    </TableRow>

</TableLayout> 

</LinearLayout>

Solution

  • First, you don't need to use xmlns:android="http://schemas.android.com/apk/res/android" for every layout, just for the root one. Second, try to just Clean the project, which forces a rebuild and regenerates R.java. Probably it just didn't recreate itself after you've altered the layout file. Under normal circumstances it should work properly. Hope this helps.