【问题标题】:Transform my simple code databinding one way to databinding two将我的简单代码数据绑定一种方式转换为数据绑定两种
【发布时间】:2019-06-19 12:52:04
【问题描述】:

我想将我的代码1 一种数据绑定一种方式转换为代码2 数据绑定两种方式是我的代码正确;如果我做得好,我不知道谢谢。

//代码1

   ‹EditText android:text="@{user.name} " 
      android : afterTextChanged ="@{callback.change}"/ >
   public void change (Editable s ) {
      final String text = s.toString(); 
      if (!text equals(name name.get()){
         name.set(text);
      }
   }

//代码2

   <EditText android:text="@={user.name} "
      android : afterTextChanged ="@={callback.change}"/ >

【问题讨论】:

    标签: android-databinding


    【解决方案1】:

    请注意 user 类中的字段 name 必须是 ObserveableField&lt;String&gt;MutableLiveData&lt;String&gt; 这样您就可以删除文本更改侦听器并添加以下内容:

    <EditText android:text="@={user.name} "/>
    

    现在Edittext 中的每个更改都将保存在name

    【讨论】:

      猜你喜欢
      • 2016-02-27
      • 2018-02-08
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多