The main layout XML file:
1 <Layoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:bind= "Http://schemas.android.com/apk/res-auto">3 4 <Data>5 6 <Importtype= "Com.liangfeizc.databinding.model.User" />7 <variable8 name= "User"9 type= "User" />Ten <variable One name= "Listener" A type= "Com.liangfeizc.databinding.listener.OkListener" /> - <variable - name= "Oktext" the type= "String" /> - </Data> - - <LinearLayout + Android:layout_width= "Match_parent" - Android:layout_height= "Match_parent" + android:orientation= "vertical"> A at <include - Android:id= "@+id/layout_input" - Layout= "@layout/layout_input" /> - - <include - Layout= "@layout/user" in Bind:user= "@{user}" /> - to <include + Layout= "@layout/layout_btn_ok" - Bind:oktext= "@{oktext}" the Bind:listener= "@{listener}"/> * </LinearLayout> $ </Layout>
This layout contains a total of 3 include layouts, the first of which is a normal layout with no <data></data> in it, and the consideration is how to get a reference to the control by ID. Binding.layoutInput.etName binding is the bound object, Layoutinput and Etname is the ID, as for why there is no underscore _, because this ID is automatically generated.
The second layout, which needs to pass the user's Pojo class, is introduced in <data>, but it also needs to define a category (see the second line of the code above) to pass the user object.
The third layout is more complex and requires passing listener and text, as well as a category to be passed.
This section references the code.
Android databinding-requires the use of control Id,listener and a scene with include in the layout