Android databinding-requires the use of control Id,listener and a scene with include in the layout

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.