Reputation: 624
I am designing a simple search feature for my application, I have Successfully created a search icon on the toolbar of my screen. Now I'm having problems in implementing brains (working) behind the search feature
Through Android's official documentation for setting up search interface, I
came across this various procedure of creating a searchable configuration,
searchable activity, ACTION_SEARCH!
I'm new to android development, I'm having a tough time in understanding all these concepts, Can someone explain the above procedure in simple terms?
Upvotes: 3
Views: 2857
Reputation: 16976
Through Android's official documentation for setting up search interface, I came across this various procedure of creating a searchable configuration, searchable activity, ACTION_SEARCH!
I'm new to android development, I'm having a tough time in understanding all these concepts, Can someone explain the above procedure in simple terms?
Well, It's easy. First, Read the Creating a Search Interface. Second, Starts from here by adding an xml in the res/xml/
project directory.
Then, You'll need to create a Searchable Activity by following link:
Creating a Searchable Activity
After creating the Searchable Activity
, You'll need to declare it on AndroidManifest.xml
, Just add the following to your SearchableActivity
:
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
After all these, Read this : PerformingSearch And Receive the query from your Activity when user do the searches(Like MainActivity
to SearchableActivity
).
Upvotes: 1
Reputation: 27
Inflate the XML menu resource (res/menu/options_menu.xml) in the onCreateOptionsMenu() method of your activity:and getMenu Item .Write following code
MenuItem searchItem=menu.findItem(R.id.searchMenu);
SearchView searchView=(SearchView)
MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Toast.makeText(MainActivity.this, ""+query,
Toast.LENGTH_SHORT).show();
return false;
}
Upvotes: 0