0

これが私の質問です。私はアプリケーションを設計しています。2 つの編集テキストとボタンを使用しています。そのため、最大長 4 の入力フィルターを使用し、フォーカスを他の編集テキストに設定すると、書き込み時にフォーカス パス2 番目の Edit Text に入力しますが、最初のテキストに書き込み続けます。

最初の編集テキストに 4 文字だけを入れて書き込みを停止し、最初のテキストを変更せずに 2 番目に書き込む方法はありますか?

ここに私の問題のコードの一部があります:

String inDigit = ((Button) view).getText().toString();
//Costo de venta
if (inStr.equals("0")) {
    inStr = inDigit; 
} else {
inStr += inDigit; 
}
int maxLength = 4;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
editX.setFilters(FilterArray);
editX.setText(inStr);

if(editX.getText().toString().length() == 4)
{
    if(editX.hasFocus()){
        editY.requestFocus();
        return;
    }

    }else {
        editY.getText().toString();
        editY.setText("");
    }

    if (lastOperator == '=') {
        result = 0;
        lastOperator = ' ';
    }
4

1 に答える 1

1

最初の編集テキストに 4 文字だけを入れる方法はありますか?

はい。edit最初の EditText が2 番目のクラス変数に呼び出されると仮定しましょうedit2TextWatcherを使用して、4 番目の文字を超えたらフォーカスeditを切り替えます。edit2

edit.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {}

    @Override
    public void afterTextChanged(Editable s) {
        if(s.length() == 4) {
            edit2.requestFocus();
        }
    }
});
于 2012-10-04T20:38:55.437 に答える