Search Item On Action Bar Android
First of all see what I have done yet. This is my menu.xml file. -
Solution 1:
http://developer.android.com/training/search/setup.html
Go through this. It explains how to setup search view in actionbar and add textchangelistner for searchview in onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
TextView textView=(TextView)findViewById(R.id.aa);
textView.setText(newText);
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
TextView textView=(TextView)findViewById(R.id.aa);
textView.setText(query);
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
return true;
}
Post a Comment for "Search Item On Action Bar Android"