如何在 Android 的下拉列表中添加 sections/headers?

How to add sections/headers in a dropdown for Android?

基本上,我使用的是 AutoCompleteTextView,它使用 Objects 的 ArrayAdapter。

搜索 Object 时,我希望使用分隔符或某种 headers 来对将显示在下拉列表中的 objects 进行分类。

我尝试在谷歌上搜索示例,但无济于事。至少,我只需要有关如何执行此操作的顶级指导。一些代码示例会很好。

到目前为止,我已经为下拉列表中的 Object 行自定义了 xml 布局。但不确定如何添加 headers/sections.

您不能将自定义视图添加到位于第一个位置的适配器吗?

    @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
}