Android: how to make keyboard enter button say Search and handle its click?
In the layout set your input method options to search.
<EditText
android:imeOptions="actionSearch"
android:inputType="text" />
In the java add the editor action listener.
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
Trying to make the soft keyboard enter button say search or display search magnifying glass and handle its click for an EditText
Remove
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
from your EditText
and it will fix your problem.
The conflict was due to the android:digits
is set. In this situation android:inputType
is set to numeric
by default disregarding what you entered there(android:inputType="text|textNoSuggestions|textVisiblePassword"
) in your xml, thus making your android:imeOptions="actionSearch"
irrelevant.
Hope it helps.
Handling physical keyboard's Enter key in SearchView
That's how I've handled it:
//Grab de EditText from the SearchView
EditText editText = (EditText) viewHolder.mTextSearch
.findViewById(android.support.v7.appcompat.R.id.search_src_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int keyAction, KeyEvent keyEvent) {
if (
//Soft keyboard search
keyAction == EditorInfo.IME_ACTION_SEARCH ||
//Physical keyboard enter key
(keyEvent != null && KeyEvent.KEYCODE_ENTER == keyEvent.getKeyCode()
&& keyEvent.getAction() == KeyEvent.ACTION_DOWN)) {
new SearchForEquipmentTask(false, viewHolder.mTextSearch
.getQuery().toString()).execute();
return true;
}
return false;
}
});
Thanks for your help!
See also:
- Grab the EditText element from a SearchView
- Android: how to make keyboard enter button say "Search" and handle its click?
Handling Enter and search key on the keyboard
I had to create two diffrent keyboard xml one with enter button and another with backspace. I have to type in edittext keyboard with backspace button apear and when type in search bar then keyboard with enter button apear.
Android keyboard Go button to Search
TrymyEditText.setImeActionLabel("Search",EditorInfo.IME_ACTION_UNSPECIFIED)
. IME_ACTION_UNSPECIFIED
allows you to put whatever text you want in the button.
Handle Enter button soft keyboard
You can use
android:imeActionLabel="your text here"
android:imeOptions="actionNext"
for next imeoption
and
android:imeActionLabel="your text here"
android:imeOptions="actionSend"
for the done button
How to set edittext to show search button or enter button on keyboard?
Use the code to edit EditText attribute
<EditText android:imeOptions="actionSearch" />
Then do this in your java code:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
Related Topics
How to 'Restart' an Android Application Programmatically
Get Certificate Fingerprint from Android App
Android: Autocompletetextview Show Suggestions When No Text Entered
Android Download Manager Completed
Gatt Callback Fails to Register
How to Draw Rounded Rectangle in Android Ui
Update Listview Dynamically with Adapter
Get JSON Data from Url Using Android
Gradle Version 2.2 Is Required. Current Version Is 2.10
How to Perform an SQLite Query Within an Android Application
Edittext Underline Below Text Property
Get All Messages from Whatsapp
Designing an Android Tablet-Only App
How to Display a Yes/No Dialog Box on Android
Retrieving a List of Users Who Have Registered Using Firebase Auth