0

test.xml:

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <include
        android:id="@+id/include_content"
        layout="@layout/content" />

    </FrameLayout>
 </layout>

content.xml:

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

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="test button"/>
  </FrameLayout>
</layout>

Java Code:

@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {

    super.onCreate(savedInstanceState, persistentState);
   TestBinding binding=DataBindingUtil.setContentView(this, R.layout.test);       
          Button button = binding.includeContent.button;

}

when i run the application , Android studio build error 'cannot find symbol variable includeContent'

what do i miss?

ZeeBm Chan
  • 59
  • 9

1 Answers1

1

check this answer.
basically, if you use 1.0-rc3 or below, you need to pass a value to included layout.
if you use 1.0-rc4 or later, it should work without passing a value.

Android Data Binding using include tag

Community
  • 1
  • 1
yshrsmz
  • 1,179
  • 2
  • 15
  • 33
  • @ZeeBmChan your welcome, please mark this as an answer, so that this can help others! – yshrsmz Nov 21 '15 at 15:03
  • what is this 1.0-rc3 1.0-rc4? There is no dependency. We only need to mark android.buildFeatures.dataBinding to true in gradle – BabyishTank Jun 27 '21 at 00:39
  • 1
    Please check the date. This is a really old question & answer. At that time, we don't have the option you mentioned, and the lib is not mature enough – yshrsmz Jul 01 '21 at 05:52