Reputation: 12656
I've implemented a keyword search in my app but I don't get any callbacks when I tap the search (i.e. question mark) key on the soft keyboard. I've added a TextWatcher to my EditText but it isn't called when I tap search. Activity.onKeyUp() isn't called either.
Is there any way to know when the user taps the search key on the soft keyboard?
Thanks in advance...
Upvotes: 0
Views: 113
Reputation: 1248
use searchView like this
SearchView sv=(SearchView)findViewByid(R.id.sv);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
//here is when clicking the search button in keyboard
}
@Override
public boolean onQueryTextChange(String s) {
//here is when the text change
return false;
}
});
Edit i've found away to do that :
in the xml
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:imeOptions="actionSearch"
android:inputType="text"/>
in the onCreate methode
((EditText)findViewById(R.id.editText)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Toast.makeText(MainActivity.this,"searching",Toast.LENGTH_LONG).show();
return true;
}
return false;
}
});
that's all
Upvotes: 1