如何在searchView中收听键盘搜索按钮 [英] how to listen to keyboard search button in searchView
本文介绍了如何在searchView中收听键盘搜索按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个SearchView.当用户单击键盘搜索按钮时,我需要进行服务器呼叫.侦听器的代码是什么样的?我在想我必须使用OnClickListener.但是,由于知道它是搜索按钮的内部代码,所以我不确定如何确定它.
I have a SearchView. When the user clicks on the keyboard search button, I need to make a server call. What does the code for the listener look like? I am thinking I have to use OnClickListener. But the internal code for knowing it's the search button, I am not sure how to determine that.
推荐答案
我已经这样做了
onQueryTextSubmit
是您要寻找的方法.
在搜索视图中设置setOnQueryTextListener
.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
MenuItem searchItem = menu.findItem(R.id.search_city);
searchView = (SearchView) searchItem.getActionView();
searchView.setQueryHint("Search View Hint");
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
//Log.e("onQueryTextChange", "called");
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
// Do your task here
return false;
}
});
return true;
}
希望获得帮助
这篇关于如何在searchView中收听键盘搜索按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文