Nactus
Nactus

Reputation: 712

How to check if an adapter filter doesn't correspond to any entries in a listview

Does "getFilter().filter();" on a simple adapter have a way to check if a listview has that particular entry ?

I have this code:

String tempString = searchField.getText().toString();

    if (tempString != "") {
         MainActivityFragment.adapter.getFilter().filter(tempString);
         MainActivityFragment.actionbar.setSubtitle("Search Results");
    }

    else {

        Toast.makeText(getActivity().getBaseContext(), "The Search Field can't be empty !", Toast.LENGTH_SHORT).show();


    }

I'd like to know if "filter(tempString);" is true (it exists in a particular listview). If not maybe prompt the user with a message.

Upvotes: 0

Views: 42

Answers (2)

indivisible
indivisible

Reputation: 5012

There is a similar question here that may or may not be a duplicate so I'll just link this here: android - listview filter count.

You can count the results after applying a filter. Unless your question was about knowing before hand; if that's the case then please edit your question to specify so and we can try a different solution.

Upvotes: 1

Rod_Algonquin
Rod_Algonquin

Reputation: 26198

Filter method is started asynchronous as what the documentation said:

Starts an asynchronous filtering operation. Calling this method cancels all previous non-executed filtering requests and posts a new filtering request that will be executed later.

solution:

You could create an interface and pass it to your adapter and in the publishResults() you could count the number of filtered data in the FilterResults class by results.count()..

if the count is 0 then call ur interface and you could put your message inside that interface..

Upvotes: 1

Related Questions