Android的Databinding-需要使用控件id,listener以及布局有include的场景
2017-08-18 11:55
567 查看
主的布局xml文件:
本布局一共包含3个include布局,第一个是一个普通的布局,里面没有<data></data>, 考虑的就是如何通过id获取控件的引用。binding.layoutInput.etName binding是绑定的对象,layoutInput和etName就是Id,至于为啥没有了下划线_ , 因为这个id也是自动生成的。
第二个布局,需要传递User这个pojo类,所以要在<data>中引入,而同时也需要定义一个类别(看上面代码第二行)把user对象进行传递。
第三个布局较为复杂,需要传递listener和text,同样也需要一个类别进行传递。
本节参考代码。
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:bind="http://schemas.android.com/apk/res-auto"> <data> <import type="com.liangfeizc.databinding.model.User" /> <variable name="user" type="User" /> <variable name="listener" type="com.liangfeizc.databinding.listener.OkListener" /> <variable name="okText" type="String" /> </data> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include android:id="@+id/layout_input" layout="@layout/layout_input" /> <include layout="@layout/user" bind:user="@{user}" /> <include layout="@layout/layout_btn_ok" bind:okText="@{okText}" bind:listener="@{listener}"/> </LinearLayout> </layout>
本布局一共包含3个include布局,第一个是一个普通的布局,里面没有<data></data>, 考虑的就是如何通过id获取控件的引用。binding.layoutInput.etName binding是绑定的对象,layoutInput和etName就是Id,至于为啥没有了下划线_ , 因为这个id也是自动生成的。
第二个布局,需要传递User这个pojo类,所以要在<data>中引入,而同时也需要定义一个类别(看上面代码第二行)把user对象进行传递。
第三个布局较为复杂,需要传递listener和text,同样也需要一个类别进行传递。
本节参考代码。
相关文章推荐
- [Android]Android布局文件中的android:id="@*"属性使用方法汇总以及介绍
- Android之ScrollView滚动布局控件使用以及显示新闻网页
- Android基础_需要使用adapter的控件,以及对BaseAdapter及其中的ViewHolder进行重构(三)
- Android控件大全以及各布局空间的使用方式
- 黑马程序员-Android控件大全以及各布局控间的使用方式
- 【Android Training - Performance】提高显示布局文件的性能[Lesson 2 - 使用include标签重用Layout]
- 牛腩购物4 aspnetpager控件的使用 以及 linkbutton 如何传值,判断传入的id值是否为数字
- 【Android动态布局】之【使用addView方法时,如何保持已有动态控件位置不被改变】
- Android中不使用布局文件,java代码动态创建布局及控件
- Android Layout中使用include标签实现UI布局重用
- android 页面布局时定义控件ID时@id/XX和@+id/xx 有什么区别?
- Android布局整合include界面控件(重用布局)
- android: 静态XML和动态加载XML混合使用,以及重写Layout控件
- android include控件的使用
- Android布局整合include界面控件
- repeater控件的使用方法,内部控件值的取得和控制,以及分页和对指定id号的获得
- android_应用开发之(使用<include>标签重用布局)
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- android 传感器实例 以及 自定义可复用控件的使用