I want to create a layout where the user types in the artist name and when he presses search on the virtual keyboard the list of artists are displayed.
View rootView = (View) inflater.inflate(R.layout.fragment_search, container, false);
EditText searchArtist = (EditText) rootView.findViewById(R.id.searchArtist);
searchArtist.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
makeToast();
return true;
}
return false;
}
});
Here is my xml
<EditText
android:id="@+id/searchArtist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/search_artist"
android:imeOptions="actionSearch"
android:inputType="text">
<requestFocus />
I have searched a lot in other stackoverflow post regarding this but none of the solutions seem to be working.
MinSDK 21, Testing on nexus 6, compileSdkVersion 22, buildToolsVersion '22.0.1'.
Also note that the searchArtist(edittext) is inside a fragment.
More context: the listener code is inside onCreateView method.