Articles → Android → Filter Data In Arrayadapter

Filter Data In Arrayadapter






Sample Code




<adapter_instance>.getFilter().Filter(text);




  1. text parameter is not case sensitive.
  2. 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


Picture showing the output of Filter data in arrayadapter
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, November 13, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250