I have a SearchView
in a ActionBar
. Now I want to use it but I don't know how to use it. In the custom SearchView
I use it like this:
SearchView sear = (SearchView) findViewById(R.id.searchView);
sear.setOnQueryTextListener(new SearchView.OnQueryTextListener()
{
@Override
public boolean onQueryTextSubmit (String query){
return false;
}
@Override
public boolean onQueryTextChange (String newText){
listDataAdapter.getFilter().filter(newText);
return true;
}
}
);
Now I have SearchView
in an action bar which I show through code:
public class DataListActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_list_layout);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
// Inflate menu to add items to action bar if it is present.
inflater.inflate(R.menu.menu_main, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
android.support.v7.widget.SearchView searchView =
(android.support.v7.widget.SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(getApplicationContext(),MainMenu.class);
startActivity(intent);
return true;
case R.id.action_Exit:
openExit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void openExit() {
}
How can I use SearchView
? I don't know how to use SearchView
in action bar.
设置onQueryTextListener(..)类似于在searchView问题中提到的内容。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.