i have a listview that displays a set of rows, each row is clickable. now, i wish to group similar type of rows under one header something like as shown in the figure (mocked up). could some please advise or provide an approach for this.
group similar rows in listview based on their content
Asked Answered
What kind of adapter are you currently using? Are you interested in how to display "separator" list items? –
Serg
+1 for the easy to understand paintings –
Ramirez
I want to perform this same task, but all the values will be updated run-time. please suggest me how to do this, I tried alot but getting repeated section list. In all not getting success. –
Syndic
Add an extra paremeter for the 'category' of each listview item. Then implement something like 'StickyListHeaders' based on that parameter.
I've used AmazingListView in the past with some effectiveness.
It is an implementation of the Google I/O Schedule App suggested approach.
Things that I like about it:
- Sticky headers
- Pagination with lazy loading
Of note:
- It's an SVN-based project
- You need to include it as a library
- It's harder to use it with Android Studio; much easier with ADT.
(I did just post a question about this recently)
Here's an image from the project home page:
If your adapter is Cursor based then use SectionCursorAdapter 2.0, you can't do simplier:
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);
}
}
}
© 2022 - 2024 — McMap. All rights reserved.