• Android的Databinding-需要使用控件id,listener以及布局有include的场景


    主的布局xml文件:

     1 <layout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:bind="http://schemas.android.com/apk/res-auto">
     3 
     4     <data>
     5 
     6         <import type="com.liangfeizc.databinding.model.User" />
     7         <variable
     8             name="user"
     9             type="User" />
    10         <variable
    11             name="listener"
    12             type="com.liangfeizc.databinding.listener.OkListener" />
    13         <variable
    14             name="okText"
    15             type="String" />
    16     </data>
    17 
    18     <LinearLayout
    19         android:layout_width="match_parent"
    20         android:layout_height="match_parent"
    21         android:orientation="vertical">
    22 
    23         <include
    24             android:id="@+id/layout_input"
    25             layout="@layout/layout_input" />
    26 
    27         <include
    28             layout="@layout/user"
    29             bind:user="@{user}" />
    30 
    31         <include
    32             layout="@layout/layout_btn_ok"
    33             bind:okText="@{okText}"
    34             bind:listener="@{listener}"/>
    35     </LinearLayout>
    36 </layout>


    本布局一共包含3个include布局,第一个是一个普通的布局,里面没有<data></data>, 考虑的就是如何通过id获取控件的引用。binding.layoutInput.etName   binding是绑定的对象,layoutInput和etName就是Id,至于为啥没有了下划线_ , 因为这个id也是自动生成的。

    第二个布局,需要传递User这个pojo类,所以要在<data>中引入,而同时也需要定义一个类别(看上面代码第二行)把user对象进行传递。

    第三个布局较为复杂,需要传递listener和text,同样也需要一个类别进行传递。

    本节参考代码。



  • 相关阅读:
    SlideShare
    准备SCJP考试
    Sun的过去
    shardingjdbc基础教程
    上万页大数据量的分页查询方案
    shardingjdbc教程 看这一篇就够了
    微服务化的认识
    JDK9对String底层存储的优化
    水平分表
    深入理解Java中的字段与属性的区别
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/7388875.html
Copyright © 2020-2023  润新知