10

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
        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?

inazaruk
  • 74,247
  • 24
  • 188
  • 156
Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
  • See the top answer to http://stackoverflow.com/questions/2119072/android-how-to-do-something-after-user-clicks-on-my-edittext – AndrewKS May 25 '11 at 21:29
  • http://stackoverflow.com/questions/2119072/android-how-to-do-something-after-user-clicks-on-my-edittext/2284973#2284973 – Robert Strauch May 25 '11 at 21:38

1 Answers1

0

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..

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123