0

我有用于编辑文本的通用文本观察器。我使用 setError() 对 editext 进行了验证,如下所示

private class GenericTextWatcher implements TextWatcher {

        private View view;

        private GenericTextWatcher(View view) {
            this.view = view;
        }

        // @Override
        public void afterTextChanged(Editable editable) {
            switch (view.getId()) {
            case R.id.autocompletetextview:

                isAlphaNumeric = validateEditText("^[a-zA-Z0-9 ,.-]*$", editLocation.getText().toString());

                if (!isAlphaNumeric) {
//                  editLocation.setError(getErrorMsg("Only , . and - are allowed"));
                    editLocation.setError(getText(R.string.invalid_loc_address));
                } else {


                }

            }
        }

        // @Override
        public void beforeTextChanged(CharSequence sequence, int start, int count, int after) {
        }
![enter image description here][1]
        // @Override
        public void onTextChanged(CharSequence sequence, int start, int before, int count) {

        }

    }

我正在使用的验证与 edittext 重叠,并且 editext 中的值不可见。是否可以转移错误消息?请为该问题提出合适的解决方案

4

1 回答 1

0

将 Textview 组件放入您的 xml 文件中。给 id tvError

TextView tvError = (TextView)findViewById(R.id.tvError);

private class GenericTextWatcher implements TextWatcher {

        private View view;

        private GenericTextWatcher(View view) {
            this.view = view;
        }

        // @Override
        public void afterTextChanged(Editable editable) {
            switch (view.getId()) {
            case R.id.autocompletetextview:

                isAlphaNumeric = validateEditText("^[a-zA-Z0-9 ,.-]*$", editLocation.getText().toString());

                if (!isAlphaNumeric) {

                    tvError.setText(getText(R.string.invalid_loc_address));
                } else {


                }

            }
        }

        // @Override
        public void beforeTextChanged(CharSequence sequence, int start, int count, int after) {
        }

        // @Override
        public void onTextChanged(CharSequence sequence, int start, int before, int count) {

        }

    }
于 2013-06-06T07:02:38.080 回答