0

I have the followig list:

List<String> item = new ArrayList<String>();

It contains a list with fruites. How to filter the list after the first 1 or 2 or three characters from an element (startsWith()) and display the first element from the list after it is filtered?

Can someone please give me an example?

Appreciate!!

just ME
  • 1,819
  • 6
  • 32
  • 53

2 Answers2

0

you can use collection for this

 Collections.sort(item, new Comparator<String>() {
    @Override
    public int compare(String s1, String s2) {
        return s1.compareToIgnoreCase(s2);
    }
});
Ram kiran Pachigolla
  • 20,647
  • 14
  • 56
  • 74
0

Here what you are looking for.

How to make a nice looking ListView filter on Android

Android Custom ListView Filtering

OR

This can help you.

  1. Add TextWatcher to EditText#addTextChangedListener
  2. In onTextChanged add or remove items from your ListView's adapter.

If you are subclassing ArrayAdapter it would have add and remove methods.

This will surely help you.

Community
  • 1
  • 1
SALMAN
  • 3,967
  • 1
  • 26
  • 21