クラスメンバー
private MyTextWatcher mTextWatcher;
private EditText mEditText;
onCreate などの適切な場所で setTextWatcher() を呼び出します。
public void setTextWatcher()
{
mTextWatcher = new MyTextWatcher();
mEditText.addTextChangedListener(mTextWatcher);
}
MyTextWatcher クラス
public class MyTextWatcher implements TextWatcher
{
@Override
public void afterTextChanged(Editable s)
{
String text = mEditText.getText().toString();
if (text.length() > 1)
{
mEditText.removeTextChangedListener(mTextWatcher);
mEditText.setText(text.substring(1));
Selection.setSelection(mEditText.getText(), 1);
mEditText.addTextChangedListener(mTextWatcher);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
}
}