简体   繁体   English

Android中AutoCompleteTextView的页眉和页脚

[英]Header and footer for AutoCompleteTextView in android

I have AutoCompleteTextView attached to my view, and used ArrayAdapter to populate for list of items. 我在视图上附加了AutoCompleteTextView,并使用ArrayAdapter填充了项目列表。 But I am unaware of how to add header and footer view for AutocompleteTextView drop down's item. 但是我不知道如何为AutocompleteTextView下拉菜单项添加页眉和页脚视图。

I know we can add header and footer in listview. 我知道我们可以在listview中添加页眉和页脚。

Any suggestions ? 有什么建议么 ?

On an AutoCompleteTextView, you don't have direct access to the DropDownListView, that's why you cannot add header and footer views there. 在AutoCompleteTextView上,您没有直接访问DropDownListView的权限,因此无法在此处添加页眉和页脚视图。

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 以下是有关如何为列表视图中的不同行提供不同布局的一些信息: Android ListView每行具有不同的布局

Android provided methods like addHeaderView(View v) and addFooterView(View v) to define headers and footers for the ListViews. Android提供了诸如addHeaderView(View v)和addFooterView(View v)之类的方法来定义ListViews的页眉和页脚。

To find an answer on your question, I can refer you to Android: Adding static header to the top of a ListActivity . 要找到您问题的答案,我可以推荐您使用Android:在ListActivity的顶部添加静态标头

Good luck! 祝好运!

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 自动完成功能应在其中返回字符串的arraylist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM