0

我喜欢在按钮单击中为 edit_text 设置文本观察器。文本观察器应仅在单击按钮时起作用。我在按钮单击中使用了文本观察器代码。但它不是那样工作的,它会在编辑文本更改时触发。我还尝试了以下代码。也不行。

edt_zip.setImeOptions(EditorInfo.IME_ACTION_DONE);

                    edt_zip.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                        @Override
                        public boolean onEditorAction(TextView v, int actionId,
                                KeyEvent event) {
                            if (actionId == EditorInfo.IME_ACTION_DONE) {
                                if (btn_update_reader.getText().toString()
                                        .equals("CANCEL UPDATE")) {
                                    btn_update_reader.setText("UPDATE READER");
                                }
                                return true;
                            }
                            return false;
                        }
                    });
4

1 回答 1

1

创建一个布尔变量来存储用户单击按钮时修改的文本编辑状态(真/假)。使用布尔值来防止 TextWatch 被触发。IE:

private lTextWatcherOn = false;  // set in button.OnClick()
public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (lTextWatchOn) {
              // do what is needed
        }
    }
于 2013-10-02T12:46:21.987 回答