How to get input from searchview to textview

我是研究僧i 提交于 2019-12-04 18:13:57

问题


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.

Or

Is there a way to transfer the input from EditText to 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());

回答1:


for searchView to editText

editText.setText(searchView.getQuery());

for editText to 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#setQuery(java.lang.CharSequence,boolean)



来源:https://stackoverflow.com/questions/20712247/how-to-get-input-from-searchview-to-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!