Naseeb Sheoran
Naseeb Sheoran

Reputation: 473

including layout in another layout

I want to include a layout in another layout in one of my application.But i am not able to do it with the help of tag.It is showing the error message that You must specifiy a layout in the include tag: .Here are the both xml files:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

      <include 
        android:id="@layout/linearlayout"


        />  
</LinearLayout>

This is the 2nd one:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearlayout"
    android:orientation="vertical"
    android:background="@color/LabelColorLight" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    >
    <naseeb.bar.DashboardLayout
        android:id="@+id/dashboard"
        android:layout_width="match_parent" 
        android:layout_height="0dip"
        android:layout_weight="1">


        <Button
            android:id="@+id/myprofile"
            style="@style/HomeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_home_myprofile"
            android:text="@string/home_myprofile" />


        <Button
            android:id="@+id/beermail"
            style="@style/HomeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/ic_home_beermail"
            android:text="@string/home_beermail" />


        <Button 
            android:id="@+id/beerstyles" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            style="@style/HomeButton"
            android:text="@string/home_beerstyles" 
            android:drawableTop="@drawable/ic_home_styles" />

        <Button 
            android:id="@+id/offlineratings" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            style="@style/HomeButton"
            android:text="@string/home_offlineratings" 
            android:drawableTop="@drawable/ic_home_offline" />

        <Button 
            android:id="@+id/places" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            style="@style/HomeButton"
            android:text="@string/home_places" 
            android:drawableTop="@drawable/ic_home_places" />

        <Button 
            android:id="@+id/top50" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            style="@style/HomeButton"
            android:text="@string/home_top50" 
            android:drawableTop="@drawable/ic_home_top50" />

        <Button 
            android:id="@+id/events" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            style="@style/HomeButton"
            android:text="@string/home_events" 
            android:drawableTop="@drawable/ic_home_events" />

        <Button 
            android:id="@+id/bycountry" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            style="@style/HomeButton"
            android:text="@string/home_bycountry" 
            android:drawableTop="@drawable/ic_home_bycountry" />
    <!--    <Button 
            android:id="@+id/naseeb"
            android:drawable="@drawable/ic_launcher"
            />  -->

    </naseeb.bar.DashboardLayout>
    </LinearLayout>
    <!--     <Button
        android:id="@+id/drinking_status"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10dp"

        android:padding="10dip"
        android:background="@color/Orange" 
        android:gravity="center"
        android:visibility="gone" /> -->

Please tell me how to solve this problem.

Upvotes: 2

Views: 682

Answers (1)

wsanville
wsanville

Reputation: 37516

Your include tag should have a layout attribute. The id is used like any other element.

<include android:id="@+id/whatever" layout="@layout/linearlayout" />

Also, like any other tag, the id attribute is not required.

Upvotes: 9

Related Questions