我有一个列表视图,显示一组行,每行都是可点击的。 现在,我希望在一个标题下对相似类型的行进行分组,如图所示(模拟)。有些人可以为此提供建议或提供方法。
答案 0 :(得分:1)
为每个listview项目的“类别”添加额外的参数。然后基于该参数实现类似'StickyListHeaders'的东西。
答案 1 :(得分:0)
我过去曾使用过AmazingListView并且有效。
Google I/O Schedule App建议方法的实现。
我喜欢它的事情:
值得注意的是:
(I did just post a question about this recently)
这是项目主页上的图片:
答案 2 :(得分:-1)
如果你的适配器是基于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);
}
}
}