Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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/google-sheets/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 如何在自定义阵列适配器中实现分段标头?_Java_Android_Listview_Header_Selection - Fatal编程技术网

Java 如何在自定义阵列适配器中实现分段标头?

Java 如何在自定义阵列适配器中实现分段标头?,java,android,listview,header,selection,Java,Android,Listview,Header,Selection,在下面的代码中,如何在自定义列表适配器中使用节标题,通过创建日期字段分隔列表项 这是我的自定义适配器代码 private class MyCustomAdapter extends ArrayAdapter<ReportItem> { private ArrayList<ReportItem> stateList; public MyCustomAdapter(Context context, int textViewResourceId,ArrayL

在下面的代码中,如何在自定义列表适配器中使用节标题,通过创建日期字段分隔列表项

这是我的自定义适配器代码

private class MyCustomAdapter extends ArrayAdapter<ReportItem> 
{
    private ArrayList<ReportItem> stateList;

    public MyCustomAdapter(Context context, int textViewResourceId,ArrayList<ReportItem> stateList) 
    {
        super(context, textViewResourceId, stateList);
        this.stateList = new ArrayList<ReportItem>();
        this.stateList.addAll(stateList);
    }

    private class ViewHolder 
    {
        TextView title;
        TextView city;
        TextView category;
        TextView created;
        TextView tags;

    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {

        ViewHolder holder = null;

        Log.v("ConvertView", String.valueOf(position));

        if (convertView == null) 
        {
            LayoutInflater vi = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = vi.inflate(R.layout.reports_list_item, null);

            holder = new ViewHolder();

            holder.title = (TextView) convertView.findViewById(R.id.textView1);
            holder.city = (TextView) convertView.findViewById(R.id.textView2);
            holder.category = (TextView) convertView.findViewById(R.id.textView3);
            holder.created = (TextView) convertView.findViewById(R.id.textView4);
            holder.tags = (TextView) convertView.findViewById(R.id.textView5);

            convertView.setTag(holder);
        } 

        else 
        {
            holder = (ViewHolder) convertView.getTag();
        }

        ReportItem county_obj = reportsListO.get(position);

        holder.title.setText(removeSpecialChars(county_obj.getTitleP()));
        holder.city.setText(removeSpecialChars(county_obj.getCity()));
        holder.category.setText(removeSpecialChars(county_obj.getCategoryP()));
        holder.created.setText(editTimeFormat(county_obj.getCreatedP()));
        holder.tags.setText(removeSpecialChars(county_obj.getTags()));


        return convertView;
    }

}

你试过用谷歌搜索吗?你会在第一页上找到很多教程。是的,我找到了很多关于简单适配器的教程,但对我的自定义适配器不起作用:有什么问题?看看这个教程:谢谢。。。我会试试这个,然后告诉你这是否有效