0

我有 8 个编辑文本,每个文本只允许一个字符。当用户输入内容时,它会自动移动到下一个编辑文本。使用 onTextchanged 可以正常工作。但是我也需要向后移动,就像用户输入后退按钮时它会自动移动到上一个编辑文本,当输入内容时它会再次移动下一个编辑文本。我该怎么做。请任何人帮忙。

任何帮助将不胜感激。

editText_Pin1.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start,int before, int count) {
                if(editText_Pin1.getText().toString().length()==1) {    //size as per your requirement {
                    editText_Pin2.requestFocus();
                }

            }
            public void beforeTextChanged(CharSequence s, int start,int count, int after) {

            }
            @Override
            public void afterTextChanged(Editable arg0) {

            }
         });
4

3 回答 3

1

尝试这样的事情......

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            if(editText_Pin2.getText().toString().length()==1){//Here you will check the last editField which has lenght == 1 
                        editText_Pin1.requestFocus();
                        return false;//This will make sure your activity doesn't gets finished
            }
       }
        return super.onKeyDown(keyCode, event);
    }

希望这可以帮助..

于 2013-05-22T11:43:06.227 回答
0

你有几个选择:

  1. Activity.onBackPressed()
  2. Activity.onKeyDown()Activity.onKeyUp()
  3. 每个 EditTexts 上的View.setOnKeyListener()
  4. View.onKeyPreIme()

我可能会选择 #1 或 #3

于 2013-05-22T11:52:42.643 回答
0

you can do it by oveeriding the onBackPressed method

@Override
public void onBackPressed() {
    //check here which edittext has current focus,change the focus to previous edittext
    //you can use edittext array also.And also check if it is the first edittext then do nothing
    return;
}
于 2013-05-22T11:44:18.797 回答