android:afterTextChanged 和 android:onTextChanged 可以用于EditText中
以输入账号密码来进行模拟,模拟使用android:onClick、android:afterTextChanged 和 android:onTextChanged 。跟我一起来做!
修改Bean类:
username 和 password 分别表示账号和密,用final来修饰,如果你不知道为什么我要用final修饰,请看我第四篇文章------Android 安卓DataBinding(四)·单向绑定 ObservableField
package com.lkdot.data;
import android.databinding.ObservableField;
public class DataBean {
public final ObservableField username;
public final ObservableField password;
public DataBean(ObservableField username, ObservableField password) {
this.username = username;
this.password = password;
}
public ObservableField getUsername() {
return username;
}
public ObservableField getPassword() {
return password;
}
}
MainActivity.java
写出 Listener 内部类,不要忘记 activityMainBinding.setListener(new Listener()); 哦!!!
package com.lkdot.data;
import android.annotation.SuppressLint;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableField;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Toast;
import com.lkdot.data.databinding.ActivityMainBinding;
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding activityMainBinding;
private DataBean dataBean;
@SuppressLint({“SetTextI18n”, “InlinedApi”})
@Override
protected void onC