OnEditorActionListener called twice with same eventTime on SenseUI keyboard
I think if you return true, it means that you are interested in the rest of the events until it reaches IME_ACTION_DONE. So if you return false, it means that you are not interested in the events and that other views will then have the opportunity to handle it. Since you only have 1 view, I suggest you just ignore the actionId check and just return false every time.
etMovieName = (EditText) view.findViewById(R.id.et_movie_name);
etMovieName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView tv, int actionId, KeyEvent event) {
System.out.println("actionId= "+ actionId);
performSearch();
return false;
}
});
Other situation is if you have overlapping views or a sibling view, then you can use actionId to pass information around. In this situation, returning true will allow you to pass info to the other view. If you really are interested in the event/actionId (for example if you have another sibling view), then you can do this:
etMovieName = (EditText) view.findViewById(R.id.et_movie_name);
etMovieName.setImeOptions(EditorInfo.IME_ACTION_DONE);
etMovieName.setSingleLine();
etMovieName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView tv, int actionId, KeyEvent event) {
System.out.println("actionId= "+ actionId);
return performSearch(); }
});
Notice the actionId value has changed to 6 once I added:
etMovieName.setImeOptions(EditorInfo.IME_ACTION_DONE);
etMovieName.setSingleLine();
(EditText) passwordView = (EditText) findViewById(R.id.password);
passwordView.setImeOptions(EditorInfo.IME_ACTION_DONE);
passwordView.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
String input;
if(actionId == EditorInfo.IME_ACTION_DONE)
{
input= v.getText().toString();
Toast toast= Toast.makeText(LogIn.this,input,
Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
return true;
}
return false;
}
});
As mitch said, you have to check the event action:
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event == null || event.getAction() != KeyEvent.ACTION_DOWN)
return false;
// do your stuff
return true;
}
This snippet works on both the Sense UI and the emulator.