1

Basically, I'm using an AutoCompleteTextView and it uses an ArrayAdapter of Objects.

When searching for Objects, I want to have separators or headers of some sort to categorize the objects that will be shown in the dropdown.

I've tried googling for examples to no avail. At the very least, I just need a top level guidance on how to do this. Some code examples would be nice.

So far, I have a custom xml layout for the Object rows in the dropdown. But not sure on how to add the headers/sections.

Ebad Saghar
  • 1,107
  • 2
  • 16
  • 41

1 Answers1

1

Couldnt you add a custom view to your adapter that is placed in the first position ?

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            convertView = inflater.inflate( R.layout.list_row_layout, parent, false);
        if (position == 0) {
            //insert custom header layout into adapter 
        }else { //load the rest of your items
}
Doug Ray
  • 988
  • 2
  • 9
  • 29
  • this is close to what I initially wanted. But here is my problem: imagine filtering the adapter so that suggestions show up based on a search. Now the search is out of order. if i type something like grapes, the suggestions would show grapes (fruit) and grape (juice). I want to divide the filtered results by their CATEGORY (each object has a field dedicated to a specific category). – Ebad Saghar Aug 12 '15 at 18:39
  • hmmm this post may help if your main concern is about filtering. http://stackoverflow.com/questions/25058146/autocompletetextview-custom-arrayadapter-filter-performance – Doug Ray Aug 12 '15 at 19:04