0

ロック画面を作成しようとしています。ロック画面には基本的に4つの編集テキストフィールドがあり、これらのフィールドは基本的に数値入力を受け取り、数値部分を提供するのに問題はありません。

今私が抱えている問題は、テキストフィールドは1つの数値のみを取り、編集テキストフィールドはフォーカスを変更する必要があるということです。1つのフィールドに値が指定された直後に、これをどのように実現できますか?

4

3 に答える 3

0

数値のみを入力するには、次のプロパティを使用します

<EditText android:inputType="number" ... />

また

<EditText
    android:inputType="phone"
    android:digits="1234567890"
    ...
/>
于 2012-10-18T21:26:01.367 に答える
0

For only allowing numerical input (and also showing the "number"-keyboard), use the inputType-attribute of the EditText class. To only allow entering one digit into the field, you can use the android:maxLength-attibute.

Use a TextWatcher to check if the one digit has been entered into the text field and change the focus to the next field.

于 2012-10-18T21:28:04.203 に答える
0

Add a listener to each EditText for when the text changes (make sure the EditText enforces a max length of 1). The logic of this listener will check that the text is a digit and of length 1, then it'll shift focus. Here's the code:

EditText et1 = ...;
EditText et2 = ...;
EditText et3 = ...;
EditText et4 = ...;

et1.addTextChangedListener(new TextWatcher() {
   @Override
   public void onTextChanged(CharSequence s, int start, int before, int count) {
      if( s.length() == 1 && Character.isDigit(s.charAt(0)) ) {
         et2.requestFocus();
      }
   }

   @Override
   public void afterTextChanged(Editable e) { }

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

et2.addTextChangedListener(new TextWatcher() {
   @Override
   public void onTextChanged(CharSequence s, int start, int before, int count) {
      if( s.length() == 1 && Character.isDigit(s.charAt(0)) ) {
         et3.requestFocus();
      }
   }

   @Override
   public void afterTextChanged(Editable e) { }

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

et3.addTextChangedListener(new TextWatcher() {
   @Override
   public void onTextChanged(CharSequence s, int start, int before, int count) {
      if( s.length() == 1 && Character.isDigit(s.charAt(0)) ) {
         et4.requestFocus();
      }
   }

   @Override
   public void afterTextChanged(Editable e) { }

   @Override
   public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
});
于 2012-10-18T21:29:24.547 に答える