Databinding 实现双向绑定

143 阅读1分钟
1.对于android 目前支持的控件属性,用 @={user.name}
     <EditText android:text="@={user.name}" .../>
  • AbsListView android:selectedItemPosition
  • CalendarView android:date
  • CompoundButton android:checked
  • DatePicker android:year, android:month, android:day
  • NumberPicker android:value
  • RadioGroup android:checkedButton
  • RatingBar

 android:rating* SeekBar android:progress

  • TabHost android:currentTab (估计没人用)
  • TextView android:text
  • TimePicker android:hour, android:minute

2.对于android 不支持的属性

需要先定义出来

@InverseBindingAdapter(attribute = "refreshing", event = "refreshingAttrChanged")
public static boolean isRefreshing(SwipeRefreshLayout view) {
    return view.isRefreshing();
}

然后就可以用了

参考 www.jianshu.com/p/c481d1f4e…