简体   繁体   中英

Cannot refer child view on <include> through android data binding

I am new to android data binding . I am unable to refer the child view of

cannot do binding.inHeader.tvTryAgain

When trying to access child view of inHeader i can't get any suggestion of generated id's by Android data binding

main.xml

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:background="@drawable/im_bg_sign_up">

        <include
            android:id="@+id/in_header"
            layout="@layout/header_title_activity"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
</include>
</RelativeLayout>
</layout>

header_title_activity.xml

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:id="@+id/li_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="vertical">

        <RelativeLayout
            android:id="@+id/re_error_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/re_title"
            android:animateLayoutChanges="true"
            android:background="@color/grey_normal"
            android:visibility="gone">


            <com.bigstar.tv.view.TextviewNormal
                android:id="@+id/tv_error_message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toLeftOf="@+id/tv_try_again"
                android:padding="5dp"
                android:text="Please fill in all the details to continue signing up"
                android:textColor="@color/white"
                android:textSize="@dimen/text_small"
                android:textStyle="normal"
                android:typeface="normal" />

            <com.bigstar.tv.view.TextviewNormal
                android:id="@+id/tv_try_again"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/retry"
                android:textColor="@color/cyan1"
                android:textSize="@dimen/text_small"
                android:textStyle="normal"
                android:typeface="normal"
                android:visibility="gone" />

        </RelativeLayout>

    </LinearLayout>

</layout>

If i have understood your question correctly i guess u want to add "include.xml" in your include tag in main.xml . For that modify your include part as:

<include
            android:id="@+id/in_header"
            layout="@layout/include"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
</include>

去掉 id 标签中的下划线并尝试清理

android:id="@+id/inHeader"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM