setare shojaei
setare shojaei

Reputation: 145

how includeing xml layout to another correctly?

I am trying to design a layout for my android app. I have a main layout that I want include to it another layout for summarizing xml code and understanding better layout for own. I write bellow xml codes but gives this error : You must specifiy a valid layout reference. The layout ID @layout/this_must_be_include is not valid. Now Can I solve my issue? Please change my code if you know what is problem. If any changes is need help me to modifying please. Thank u so much. This is main:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:id="@+id/main_scroll"
android:orientation="vertical" android:background="@color/White">


<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="3dp"
android:paddingRight="3dp" >

<LinearLayout
    android:id="@+id/liner_merge"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingLeft="4dp"
    android:paddingRight="4dp">
   <include layout="@layout/liner_merge"/>
 </LinearLayout>

</LinearLayout>

</ScrollView>

And this is xml must be included:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="@color/White">

<LinearLayout
    android:id="@+id/liner_footer1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingTop="2dp" >

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" >

        <TableRow >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:paddingLeft="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:paddingLeft="10px"
                    android:text="File name :"
                    android:textColor="@color/Black" />
            </LinearLayout>
        </TableRow>

        <TableRow >

            <LinearLayout
                android:layout_width="270dp"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:paddingRight="10dp" >

                <EditText
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="4.69"
                    android:text="Untitled"
                    android:textSize="14dp" >

                    <requestFocus />
                </EditText>
            </LinearLayout>
        </TableRow>

        <TableRow >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:paddingLeft="5dp" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:paddingLeft="10px"
                    android:text="Save path :"
                    android:textColor="@color/Black" />
            </LinearLayout>
        </TableRow>

        <TableRow >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="10dp"
                android:paddingRight="10dp" >

                <EditText
                    android:id="@+id/edPathSave"
                    android:layout_width="270dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="/mnt/sdcard/My Audios/"
                    android:textSize="14dp" />
            </LinearLayout>
        </TableRow>
    </TableLayout>
 </LinearLayout>

</LinearLayout>

Upvotes: 1

Views: 70

Answers (3)

AndroidHacker
AndroidHacker

Reputation: 3596

Simply include layout at position in another layout.

<include layout="@layout/your_layout_to_be_included"/> 

Upvotes: 0

Hariharan
Hariharan

Reputation: 24853

Your linear layout id and the name of the layout which you want to include (ie. liner_merge) are same.. Remove the id or rename the id of the linear layout..

Try this..

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:id="@+id/main_scroll"
android:orientation="vertical" 
android:background="@color/White">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="3dp"
android:paddingRight="3dp" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="4dp"
    android:paddingRight="4dp">

   <include 
      layout="@layout/liner_merge"/>

 </LinearLayout>

</LinearLayout>

</ScrollView>

Upvotes: 1

Bhanu Sharma
Bhanu Sharma

Reputation: 5145

<include
        android:id="@+id/incld"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/header" />

here layout="@layout/header" header is your layout name which you want to include in another layout just add this code in your second layout :)

Upvotes: 0

Related Questions