I have been working on Implementing Custom search
in Android
App-bar. So, I have added following code in menu_main.xml
<item android:id="@+id/action_search"
android:title="search"
android:icon="@drawable/ic_search"
app:showAsAction="ifRoom|collapseActionView"
android:hint="Enter Tags"
app:actionViewClass="android.support.v7.widget.SearchView" />
Now when I am looking at HomeActivity
. It's look like this:
It's perfectly fine!. I haven't implemented the backend code for above SearchView
. Now, I want to add some following features in above Search bar
User can search with tags (Searching with tags means that if there is a space between two words then I will treat them as tags). It's very similar to
Pintreset
app.Further I want to get these tags from
Search Bar
and put intoGet
request parameter.Screenshot
Questions
- For now, forgot about the
Style
. I just want to know How can I achieve this in mySearch Bar
? - How can I add box on every tag with this cross sign in
Android app bar
?
Any help would be appreciable.
Edit-1
I am adding onCreateOptionsMenu
method:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
if (null != searchView) {
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
}
SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
public boolean onQueryTextChange(String newText) {
// this is your adapter that will be filtered
return true;
}
public boolean onQueryTextSubmit(String query) {
//Here u can get the value "query" which is entered in the search box.
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
return super.onCreateOptionsMenu(menu);
}
I am getting the submitting text in onCreateOptionsMenu.onQueryTextSubmit
method. What should I do now?