-
Populating listview with various custom objects in separate sections
almost 9 years ago
-
almost 9 years ago
Create a custom adapter for list view, inside getview method do the following
Create an xml file
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/list_header" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="I am new header"/> <TextView android:id="@+id/item" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="i am list item"/> </LinearLayout>
// in above code please replace _ with _ (underscore) Inside get view method check the object like it belongs to which model and and then hide or show the header.
if(object belongs to the previous model object){ list_header.setVisiblity(View.GONE); }else{ list_header.setVisiblity(View.VISIBLE); list_header.setText(MODAL Class name); }
Modify the code as your requirement but logic will be same.
-
-
almost 9 years ago
Are you using same layout for list row in each section header ??
-
2 Answer(s)