0

I have AutoCompleteTextView attached to my view, and used ArrayAdapter to populate for list of items. But I am unaware of how to add header and footer view for AutocompleteTextView drop down's item.

I know we can add header and footer in listview.

Any suggestions ?

Zoombie
  • 3,590
  • 5
  • 33
  • 40

3 Answers3

1

On an AutoCompleteTextView, you don't have direct access to the DropDownListView, that's why you cannot add header and footer views there.

A solution to your problem will be to use 2 types of views in your list, and set the first/last row to have the header's/footer's layout. This can be done on the adapter, which you create yourself.

Here's some info about how to provide different layouts for different rows in a list view: Android ListView with different layouts for each row

Community
  • 1
  • 1
Udinic
  • 3,014
  • 2
  • 25
  • 32
  • Thanks for suggestion @Udinic, as you said dropdown of autocompletetextview can not be controlled in many ways {the way i wanted to}. plus header and footer view both needed for it, which need to be show/hide for some conditions for my application, Later just changed my Autocomplete textview to simple EditText and provided popupmenu for it and its well controllable :) – Zoombie Jun 27 '12 at 05:08
  • Marking your answer as accepted because it showed me that i cannot achieve customized Header/footer with AutocompleteTextView's dropdown view. – Zoombie Aug 24 '12 at 03:26
0

Android provided methods like addHeaderView(View v) and addFooterView(View v) to define headers and footers for the ListViews.

To find an answer on your question, I can refer you to Android: Adding static header to the top of a ListActivity.

Good luck!

Community
  • 1
  • 1
DroidBender
  • 7,762
  • 4
  • 28
  • 37
-1
private class PlacesAutoCompleteAdapter extends ArrayAdapter<String> implements Filterable {
    private ArrayList<String> resultList;

    public PlacesAutoCompleteAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }

    @Override
    public int getCount() {
        return resultList.size();
    }

    @Override
    public String getItem(int index) {
        return resultList.get(index);
    }

    @Override
    public Filter getFilter() {
        Filter filter = new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults filterResults = new FilterResults();
                if (constraint != null) {
                    // Retrieve the autocomplete results.
                    resultList = autocomplete(constraint.toString());

                    // Assign the data to the FilterResults
                    filterResults.values = resultList;
                    filterResults.count = resultList.size();
                }
                return filterResults;
            }

            @Override
            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null && results.count > 0) {
                    notifyDataSetChanged();
                }
                else {
                    notifyDataSetInvalidated();
                }
            }};
        return filter;
    }
}

where autocomplete function should return the arraylist of string

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Deepak Goel
  • 5,624
  • 6
  • 39
  • 53