Najeebullah Shah
Najeebullah Shah

Reputation: 3709

Android: Edittext advance filter for searching in listview

I have a EditText and a ListView right now i am filtering the listview with the help of the text in edit text by using method contains(someString). But actually i want to search in the scenario where like edit text has text i.e. ABC Product. Now i want the search to show all the rows with either ABC or Product in it. Say for example the list with the above mentioned search will show ABC Item and XYZ Product. Is there any default method for this or i have to use custom functionality for this.

Upvotes: 0

Views: 485

Answers (2)

Vishnu
Vishnu

Reputation: 13

inputSearchText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
             // When user changed the Text
             YourActivity.this.adapter.getFilter().filter(cs);

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    });

Upvotes: 0

g00dy
g00dy

Reputation: 6778

Well not exactly default, but you'll have to perform contains() twice. What I mean is if you split() the search string (from the EditText on the space " " symbol), you can have the two words, then perform contains() for each one of them.

Upvotes: 1

Related Questions