我正在使用 textWatcher :
final EditText et = (EditText) findViewById(R.id.editText1);
final TextView tv = (TextView) findViewById(R.id.textView2);
et.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s){
if(s.length() > 0) {
tv.setText(s.toString().substring(s.length()-1));
et.setText("");
}
}
public void beforeTextChanged(CharSequence s,int start,int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
这个返回错误,我无法访问et.setText,因为它可能是最终的或者因为它被键盘锁定了,知道吗?
日志猫:
06-02 13:35:25.139: D/AndroidRuntime(12532): Shutting down VM
06-02 13:35:25.139: W/dalvikvm(12532): threadid=1: thread exiting with uncaught exception (group=0x40018578)
06-02 13:35:25.219: E/AndroidRuntime(12532): FATAL EXCEPTION: main
06-02 13:35:25.219: E/AndroidRuntime(12532): java.lang.StackOverflowError
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView$InsertionPointCursorController.hide(TextView.java:8609)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.hideInsertionPointCursorController(TextView.java:9088)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.hideControllers(TextView.java:9105)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2677)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input$1.beforeTextChanged(Input.java:27)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.sendBeforeTextChanged(TextView.java:6554)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2702)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2662)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.EditText.setText(EditText.java:178)
06-02 13:35:25.219: E/AndroidRuntime(12532): at android.widget.TextView.setText(TextView.java:2637)
06-02 13:35:25.219: E/AndroidRuntime(12532): at com.pack.witch.Input
Ps:我需要更改用户键入的内容,例如,如果他键入“A”,我将显示“D”,这看起来就像他键入“D”