奇怪的文本框出现在搜索

时间:2015-11-18 09:22:27

标签: android

如下图所示,当用户在searchView上输入文字时,屏幕中央会出现一个黑色文本框。如何摆脱它?

enter image description here

在我的MainActivity.java中搜索相关代码

    listView.setTextFilterEnabled(true);
    searchview = (SearchView) findViewById(R.id.searchView);
    searchview.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String newText)
        {

            if (TextUtils.isEmpty(newText)) {
                listView.clearTextFilter();
            } else {
                listView.setFilterText(newText);
            }
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String query)
        {
            return false;
        }
    });

在我的MyAdapter.java上搜索相关代码

public Filter getFilter() {
    return new Filter() {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            final FilterResults oReturn = new FilterResults();
            final ArrayList<DrugItem> results = new ArrayList<DrugItem>();
            if (filteredItemsArrayList == null)
                filteredItemsArrayList = itemsArrayList;
            if (constraint != null) {
                if (itemsArrayList != null && filteredItemsArrayList.size() > 0) {
                    for (final DrugItem g : filteredItemsArrayList) {
                        if (g.getDrugGenericName().toLowerCase()
                                .contains(constraint.toString()) || g.getDrugBrandName().toLowerCase()
                                .contains(constraint.toString()))
                            results.add(g);
                    }
                }
                oReturn.values = results;
            }
            return oReturn;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint,
                                      FilterResults results) {
            itemsArrayList = (ArrayList<DrugItem>) results.values;
            notifyDataSetChanged();
        }
    };
}

public void notifyDataSetChanged() {
    super.notifyDataSetChanged();
}

在我的activity_main.xml中搜索相关代码

    <SearchView
        android:iconifiedByDefault="false"
        android:layout_below="@+id/toprow"
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:queryHint="Enter Drug Name To Filter......." />

1 个答案:

答案 0 :(得分:0)

How do I remove popup text from listview filter?

我搜索了之前作为上述链接的答案。没有解决方案。使用其他方式进行过滤而不是setTextFilterEnabled(true)