关于对文本输入框 EditText的动态监听
直接贴上源码
//自己写一个 ChangableEditText类继承与实现文本监听
public class ChangableEditText extends AutoCompleteTextView implements TextWatcher{
public ChangableEditText(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence text, int start, int before,
int after) {
Log.v("result", text + "");
}
}
//接下来看布局
//布局很简单就是一个EditText的改变
//注意一定要带上包名,否则会出错
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.example.testdialog.ChangableEditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</com.example.testdialog.ChangableEditText>
</LinearLayout>
OK,这样就可以用了
转载于:https://blog.51cto.com/670176656/1606144