作品不足EditText.OnFocusChangeListener

时间:2018-12-20 10:38:14

标签: android-edittext focuslistener

在适配器中工作不充分EditText.OnFocusChangeListener 他交替调用hasFocus = true / hasFocus = false 然后应用程序冻结

EditText.OnFocusChangeListener editorActionListener = new TextView.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        final EditText amount = (EditText) v;
        if (hasFocus) {
            if (amount.getText().toString().trim().equals("0") ||
                    amount.getText().toString().trim().equals("0.0")) {
                amount.setText("");
                return;
            }
        } else {
            if (amount.getText().toString().trim().length() == 0) {
                amount.setText("0");
                return;
            }
        }
    }
};

我希望当我将光标放在editText上时,它将变为空 如果它为空,并且我删除了光标,它将变为0

0 个答案:

没有答案