Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Android下拉列表中添加节/标题?_Java_Android_User Interface_Autocomplete_Autocompletetextview - Fatal编程技术网

Java 如何在Android下拉列表中添加节/标题?

Java 如何在Android下拉列表中添加节/标题?,java,android,user-interface,autocomplete,autocompletetextview,Java,Android,User Interface,Autocomplete,Autocompletetextview,基本上,我使用的是AutoCompleteTextView,它使用对象的ArrayAdapter 在搜索对象时,我希望使用某种分隔符或标题对下拉列表中显示的对象进行分类 我在谷歌上搜索过一些例子,但都没有用。至少,我需要一个关于如何做到这一点的顶级指导。一些代码示例会很好 到目前为止,我已经为下拉列表中的对象行定制了xml布局。但不确定如何添加标题/节。您能否将自定义视图添加到位于第一个位置的适配器中 @Override public View getView(int posit

基本上,我使用的是AutoCompleteTextView,它使用对象的ArrayAdapter

在搜索对象时,我希望使用某种分隔符或标题对下拉列表中显示的对象进行分类

我在谷歌上搜索过一些例子,但都没有用。至少,我需要一个关于如何做到这一点的顶级指导。一些代码示例会很好


到目前为止,我已经为下拉列表中的对象行定制了xml布局。但不确定如何添加标题/节。

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

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

这接近我最初想要的。但我的问题是:想象一下过滤适配器,以便根据搜索结果显示建议。现在搜索出了问题。如果我键入葡萄之类的内容,建议将显示葡萄(水果)和葡萄(果汁)。我想将过滤结果按类别进行划分(每个对象都有一个专门用于特定类别的字段)。如果您主要关心的是过滤,那么这篇文章可能会有所帮助。