存档

文章标签 ‘edittext’

android监听多个Edittext,自定义类

2014年1月13日 没有评论

为了项目需要,书写了一个自定义的android监听多个Edittext类

代码如下:

package com.myUtil;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.qianjinapp.R;

public class MyTextWatcher implements TextWatcher {

private EditText editText;

public MyTextWatcher(EditText edtText) {
setEditText(edtText);
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub

}

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
EditText noweditText = getEditText();
switch (noweditText.getId()) {
case R.id.login_phone:
//do something
break;
default:
break;
}
}

public EditText getEditText() {
return editText;
}

public void setEditText(EditText editText) {
this.editText = editText;
}
}

 

调用方法:

Edittext login_phone=(Edittext)this.findViewById(R.id.login_phone);

login_phone.addTextChangedListener(new MyTextWatcher(login_phone));

分类: android 标签: , ,
css.php