在listview中根据其内容对相似的行进行分组

我有一个列表视图,显示一组行,每行都是可点击的。 现在,我希望在一个标题下对相似类型的行进行分组,如图所示(模拟)。有些人可以为此提供建议或提供方法。     
已邀请:
为每个listview项的“类别”添加额外的参数。然后基于该参数实现类似'StickyListHeaders'的东西。     
我过去使用过AmazingListView并且有一定的效果。 它是Google I / O Schedule App建议方法的实现。 我最喜欢的事情: 粘性标题 分页与懒惰加载 值得注意的是 这是一个基于SVN的项目 您需要将其作为库包含在内 在Android Studio中使用它会更难;使用ADT更容易。 (我最近刚刚发布了一个关于此的问题) 这是项目主页上的图片:     
如果您的适配器是基于Cursor的,那么使用SectionCursorAdapter 2.0,您不能做到更简单:
public class MyAdapter extends SectionCursorAdapter<String, MyAdapter.SectionViewHolder, MyAdapter.ItemViewHolder> {

    public MyAdapter(Context context, Cursor cursor) {
        super(context, cursor, 0, R.layout.item_section, R.layout.item_title);
    }

    // this method will fullfill your wishes
    @Override protected String getSectionFromCursor(Cursor cursor) {
        return cursor.getString(cursor.getColumnIndexOrThrow("group"));
    }

// replace getView/bindView/newView
// --------------------------------------------
    @Override protected SectionViewHolder createSectionViewHolder(View sectionView, String section) {
        return new SectionViewHolder(sectionView);
    }

    @Override protected ItemViewHolder createItemViewHolder(Cursor cursor, View itemView) {
        return new ItemViewHolder(itemView);
    }

    @Override protected void bindSectionViewHolder(int position, SectionViewHolder sectionViewHolder, ViewGroup parent, String section) {
        sectionViewHolder.titleView.setText(section);
    }

    @Override protected void bindItemViewHolder(ItemViewHolder itemViewHolder, Cursor cursor, ViewGroup parent) {
        itemViewHolder.title = cursor.getString(cursor.getColumnIndexOrThrow("title"));
        itemViewHolder.titleView.setText(itemViewHolder.text);
    }

// view holders
// --------------------------------------------
    public class SectionViewHolder extends ViewHolder {
        public TextView titleView;

        public SectionViewHolder(View rootView) {
            super(rootView);
            titleView = findWidgetById(R.id.sectionText);
        }
    }

    public class ItemViewHolder extends ViewHolder {
        public String title;
        public TextView titleView;

        public ItemViewHolder(View rootView) {
            super(rootView);
            titleView = findWidgetById(R.id.titleText);
        }
    }

}
    

要回复问题请先登录注册