Articles → Android → Filter Data In Arrayadapter
Filter Data In Arrayadapter
Sample Code
<adapter_instance>.getFilter().Filter(text);
- text parameter is not case sensitive.
- Filter result will contain only those values that starts with text parameter. For example, if the value of text is ‘a’ then all the data starts with letter ‘a’ will come in filtered result.
Example
String fruitlist[] = {
"apple",
"banana",
"orange",
"cherry"
};
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter < String > adapter = new ArrayAdapter < String > (this, R.layout.support_simple_spinner_dropdown_item, fruitlist);
adapter.getFilter().filter("a");
spinner.setAdapter(adapter);
Output
Click to Enlarge