I want to put search feature to my app via SearchView
in ActionBar
- I have ListView
with some objects. When the search is submitted i want to show the data which is contained in search query to show in another activity in a ListView
. To store the data am I using Parse.com framework. I followed this easy tutorial, but I know that it is not made for searching through ListView
items, but it searches throuh globa items - downloaded apps etc.
Setting up SearchView in MainActivity.class
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
setupSearchView(searchItem);
return true;
}
private void setupSearchView(MenuItem searchItem) {
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null) {
List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
for (SearchableInfo inf : searchables) {
if (inf.getSuggestAuthority() != null
&& inf.getSuggestAuthority().startsWith("applications")) {
info = inf;
}
}
mSearchView.setSearchableInfo(info);
}
mSearchView.setOnQueryTextListener(this);
}
@Override
public boolean onQueryTextChange(String arg0) {
return false;
}
@Override
public boolean onQueryTextSubmit(String arg0) {
Toast.makeText(getBaseContext(), "submited", Toast.LENGTH_SHORT).show();
return false;
}
My Animal.class
- getters and setters (check the //note
):
@ParseClassName("Animal")
public class Animal extends ParseObject{
public Animal(){
}
public String getAnimal(){ //I want to search by these objects
return getString("animal");
}
public void setAnimal(String animal){
put("animal", animal);
}
public String getArea(){
return getString("area");
}
public void setArea(String area){
put("area", area);
}
public String getImgUrl(){
return getString("imgUrl");
}
public void setImgUrl(String imgUrl){
put("imgUrl", imgUrl);
}
public String getAbout(){
return getString("about");
}
public void setAbout(String about){
put("about", about);
}
}
Do you know, if is there some way how to customize it to search through my items in ListView? Or is there completely different but better way, how to do it?
Thanks in advance