Android 如何从searchview获取输入到textview
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20712247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get input from searchview to textview
提问by Theresa Gamit
Is there another way to get the input of searchview and put it into textview? It seems that the getText() and setText() method are not applicable to searchview.
还有另一种方法可以获取searchview的输入并将其放入textview吗?getText() 和 setText() 方法似乎不适用于 searchview。
Or
或者
Is there a way to transfer the input from EditText to Searchview?
有没有办法将输入从 EditText 传输到 Searchview?
Please help me to look for necessary resources/codes/method about the above question. Thank you. Here is my code:
请帮我寻找有关上述问题的必要资源/代码/方法。谢谢你。这是我的代码:
public boolean onQueryTextChange(String newText) {
// TODO Auto-generated method stub
showResults(newText);
return false;
}
@Override
public boolean onQueryTextSubmit(String query) {
// TODO Auto-generated method stub
tvInput = (TextView) findViewById (R.id.tvInput);
showResults(query);
// searchView.getQuery().toString();
tvInput.setText(searchView.getQuery().toString());
return false;
}
I also do it in other way. Here:
我也用其他方式做。这里:
tvInput = (TextView) findViewById (R.id.tvInput);
tvInput.setText(searchView.getQuery());
回答by gaurav5430
for searchView to editText
用于 searchView 编辑文本
editText.setText(searchView.getQuery());
for editText to SearchView
用于 editText 到 SearchView
searchView.setQuery(editText.getText(),false);
http://developer.android.com/reference/android/widget/SearchView.html#getQuery()
http://developer.android.com/reference/android/widget/SearchView.html#getQuery()