如何从searchview获取输入到textview [英] How to get input from searchview to textview

查看:143
本文介绍了如何从searchview获取输入到textview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有其他方法可以获取searchview的输入并放入textview中?看来getText() 和setText() 方法不适用于searchview.

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.

有没有办法将输入从 EditText 传输到 Searchview?

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());

推荐答案

for searchView to editText

for searchView to editText

editText.setText(searchView.getQuery());

用于将 editText 转换为 SearchView

for editText to SearchView

searchView.setQuery(editText.getText(),false);

http://developer.android.com/reference/android/widget/SearchView.html#getQuery()

http://developer.android.com/参考/android/widget/SearchView.html#setQuery(java.lang.CharSequence,boolean)

这篇关于如何从searchview获取输入到textview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆