安卓:prevent文本框弹出时,在搜索查看输入文本 [英] Android: Prevent text field pop-up when entering text in a SearchView

查看:179
本文介绍了安卓:prevent文本框弹出时,在搜索查看输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好Android开发者,

Hello Android developers,

我已经得到了Android 搜索查看部件有问题。我想要做的就是附加一个活的文本过滤器我的ListView(文字输入自动刷新筛选结果)。它的工作原理实际上是罚款,这是没有巨大的努力得到它的工作对我的ListActivity这些行:

I've got a problem with the Android SearchView widget. What I'm trying to do is to attach a "live" text filter to my ListView (text input automatically refreshes filter results). It works actually fine and it was no huge effort to get it working on my ListActivity with these lines:

private SearchView listFilter;

this.listFilter = (SearchView) findViewById(R.id.listFilter);
this.listFilter.setOnQueryTextListener(this);
this.listFilter.setSubmitButtonEnabled(false);

this.getListView().setOnItemClickListener(this);
this.getListView().setTextFilterEnabled(true);

// from OnQueryTextListener
public boolean onQueryTextChange(String newText) {
    if (newText.isEmpty()) {
        this.getListView().clearTextFilter();
    } else {
        this.getListView().setFilterText(newText);
    }
    return true;
}

和这里的XML插件声明

And here the xml widget declaration

<SearchView
    android:id="@+id/listFilter"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:iconifiedByDefault="false"
    android:queryHint="enter text to filter" />

现在我的问题是,我输入文本搜索查看每一次,一个陌生的文本框弹出,瞬间呈现,因为我刚进入这是一种无用的,因为我可以看到在搜索查看我输入自己和它相同的文字部分街区的景象在我的列表条目,这仅仅是烦人。

Now what my problem is that every time I enter text into the SearchView, a strange text field pops up instantly showing the same text as I just entered which is kind of useless since I can see my input in the SearchView itself and it partly blocks the sight on my list entries, which is just annoying.

有没有什么办法prevent从输入到搜索查看弹出的文本字段?我找不到任何财产既不在定义的XML插件选项,也没有在Java类的引用。

Is there any way to prevent that text field from popping up on typing into the SearchView? I couldn't find any property neither on the xml defined widget options nor on the java class reference.

我知道还有另一种方法使用的EditText和TextWatcher提供过滤器功能,但后来我不得不独自处理所有的过滤,无法从搜索查看利润操纵对我来说。

I know there is another way to provide the filter functionality by using EditText and TextWatcher, but then I have to handle the filtering all by myself and couldn't profit from the SearchView handling it for me.

任何建议都是AP preciated。 最好的问候

Any suggestions are appreciated. Best regards

菲利克斯

推荐答案

我发现了如何摆脱那个丑陋的弹出窗口。诀窍是用低于过滤directly.The code假设你已经在你的customAdapter实现过滤的工作。

i found out how to get rid of that ugly popup window. The trick is to work with filter directly.The code below assumes you have implemented filterable in your customAdapter.

public boolean onQueryTextChange(String newText) {
    if (TextUtils.isEmpty(newText)) {
       m_listView.clearTextFilter();
    } else {
       ContactsAdapter ca = (ContactsAdapter)lv.getAdapter();
       ca.getFilter().filter(newText);
       //following line was causing the ugly popup window.
       //m_listView.setFilterText(newText);
    }
   return true;
}

这篇关于安卓:prevent文本框弹出时,在搜索查看输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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