How to remove android searchview popup text while searching?
Asked Answered
A

2

15

I have implemented action bar SearchView , it's working fine but at the bottom of the screen a floating text popup is shown. See screenshot:

screen short

ListView Java class:

@Override
    public boolean onQueryTextChange(String newText) {

        if (TextUtils.isEmpty(newText)) {
            mListView.clearTextFilter();
        } else {

            // EventAdapterView ca = (EventAdapterView)mListView.getAdapter();
            // ca.getFilter().filter(newText.toString());

            // Filter lFilter = mDataAdapter.getFilter();
            // lFilter.filter("");
            // following line was causing the ugly popup window.
            mListView.setFilterText(newText.toString());

            // EventAdapterView ca = (EventAdapterView)mListView.getAdapter();
            // ca.getFilter().filter(newText.toString());

        }

        return true;
    }

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

Adapter class

@Override
    public Filter getFilter() {
        /**
         * A filter object which will filter message key
         * */
        Filter filter = new Filter() {

            @SuppressWarnings("unchecked")
            @Override
            protected void publishResults(CharSequence constraint,
                    FilterResults results) {

                mEventUtil = (List<EventUtil>) results.values; // has the
                                                                // filtered
                                                                // values
                notifyDataSetChanged(); // notifies the data with new filtered
                                        // values. Only filtered values will be
                                        // shown on the list
            }

            @Override
            protected FilterResults performFiltering(CharSequence constraint) {

                FilterResults results = new FilterResults(); // Holds the
                                                                // results of a
                                                                // filtering
                                                                // operation for
                                                                // publishing

                List<EventUtil> FilteredArrList = new ArrayList<EventUtil>();

                if (mOriginalValues == null) {
                    mOriginalValues = new ArrayList<EventUtil>(mEventUtil); // mOriginalValues

                }

                if (mListItem == null) {
                    mListItem = new ArrayList<String>();
                    for (EventUtil message : mOriginalValues) {
                        mListItem.add(message.getEvent_Title());
                    }
                }

                /**
                 * 
                 * If constraint(CharSequence that is received) is null returns
                 * the mOriginalValues(Original) values else does the Filtering
                 * and returns FilteredArrList(Filtered)
                 * 
                 **/

                if (constraint == null || constraint.length() == 0) {

                    /*
                     * CONTRACT FOR IMPLEMENTING FILTER : set the Original
                     * values to result which will be returned for publishing
                     */
                    results.count = mOriginalValues.size();
                    results.values = mOriginalValues;
                } else {
                    /* Do the filtering */
                    constraint = constraint.toString().toLowerCase();

                    for (int i = 0; i < mListItem.size(); i++) {
                        String data = mListItem.get(i);
                        if (data.toLowerCase().contains(constraint.toString())) {
                            FilteredArrList.add(mOriginalValues.get(i));
                        }
                    }

                    // set the Filtered result to return
                    results.count = FilteredArrList.size();
                    results.values = FilteredArrList;
                }
                return results;
            }
        };
        return filter;
    }

How can I remove this floating TextView ?

Ascendancy answered 29/11, 2013 at 4:29 Comment(6)
bottom where text is displyed is this any kind of viewSummons
how to remove it, it is posible to removeAscendancy
no that is text lableAscendancy
u can get complete source code in Android samples APIDemo-->Views-->Search view-->filter exampleAscendancy
Try to Overide onDisplayHint in ListView and do not call super inmpementation.Oarfish
where can i use onDisplayHint , in activity or adapter classAscendancy
K
31

Try this

first disable TextFilterEnabled on your ListView

yourListView.setTextFilterEnabled(false);

and filter your data like this:

android.widget.Filter filter = yourListAdapter.getFilter();


@Override
public boolean onQueryTextChange(String newText) {
    // TODO Auto-generated method stub
    filter.filter(newText);
    return true;
}

that's it, and the search popup gone like a charm

Kalil answered 4/12, 2013 at 17:41 Comment(1)
same code i have tried but the difference is u have declare filter object outside the method, but i have declared inside method , i have change it , now perfectly it working.... any way Thanks @AT_ABAscendancy
E
2

If you are using a CursorLoader then you should store the search query in a member variable for later use, instead of using the adapter's filter:

say,

private String mSearchQuery;

and then change the loader creation to work with the search query

@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
    showProgress(true);
    if (TextUtils.isEmpty(mSearchQuery)) {
        return new CursorLoader(
                mActivity,
                CONTENT_URI,
                PROJECTION,
                DEFAULT_SELECTION,
                null,
                SORT_ORDER
        );
    }
    mSearchQuery = "%" + mSearchQuery + "%";
    return new CursorLoader(
            mActivity,
            CONTENT_URI,
            PROJECTION,
            // add the filtering criteria to the default.
            DEFAULT_SELECTION + " AND " + COLUMN_A + " LIKE ?",
            new String[]{mSearchQuery},
            SORT_ORDER
    );
}

and finally, make sure that you reload the loader

@Override
public boolean onQueryTextChange(String newText) {
    mSearchQuery = newText;
    // calls the above method
    mActivity.getSupportLoaderManager().
            restartLoader(0, null, this);
    return true;
}
Eulaheulalee answered 15/5, 2014 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.