开发者

EditText needs clicking twice to open search dialog [duplicate]

开发者 https://www.devze.com 2023-03-08 05:04 出处:网络
This question already has answers here: How to do something after user clicks on my EditText (6 answers)
This question already has answers here: How to do something after user clicks on my EditText (6 answers) Closed 6 years ago.

My application has two EditText elements. Both implement the OnClickListener like this:

editText1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Open search dialog
     开发者_如何学JAVA   doSomeStuff();
        }
    });

doSomeStuff() means: Clicking on the text field opens a search dialog via onSearchRequested(). The search result is written back to the text field.

This works fine but if I click the other text field I always have to click twice before the search dialog comes up. Where does that come from and how can I change that so that the search dialog comes up when clicking only once?


For EditText fields it is better to use an OnKeyListener. With the passed in KeyEvent you can then react differently depending on how the EditText field got clicked/get focus. Otherwise you can also try a OnFocusChangeListener or if you want to use TextWatcher to see each character that is added you can implement a TextWatcher and use addTextChangedListener..

0

精彩评论

暂无评论...
验证码 换一张
取 消