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..
精彩评论