如何从listview过滤器中删除弹出文本?

han*_*j06 7 android android-listview

我在ListView上使用文本过滤器,我想摆脱显示过滤器文本的弹出视图.有没有办法删除这个视图?

一些示例代码:

    ArrayList<String> buildingNames = new ArrayList<String>();
    ListView list = (ListView)findViewById(R.id.list);

    list.setAdapter(new ArrayAdapter<String>(this, R.layout.menu_item, buildingNames));
    list.setTextFilterEnabled(true);

    list.setFilterText("test_filter");
Run Code Online (Sandbox Code Playgroud)

当我设置过滤器文本时,ListView底部会弹出一个非常丑陋的视图,显示当前过滤器文本的内容:

ListView过滤器文本弹出窗口

Chr*_*ill 8

我在这里找到答案: http://markmail.org/message/7uju6bmmaswag2lu:

通过调用setTextFilterEnabled(),您可以请求此弹出窗口.如果您不想要它,请禁用文本过滤.这是用户的交互式功能.它并不意味着以编程方式使用.如果要以编程方式过滤适配器,请直接在适配器上调用getFilter()(如果适配器支持过滤).

罗曼盖伊

因此,您需要直接使用过滤器,而不是使用setTextFilterEnabled:

CustomAdapter customAdapter = (customAdapter)myListView.getAdapter();
Filter filter = customAdapter .getFilter();
filter.filter("search string");
Run Code Online (Sandbox Code Playgroud)