-1

Hi i need a list like this right now im using expandlelist but i dont know how to get sub lists under the main like i need. V is just to show drop arrow

Title V Question V Answer Answer Answer Question V Answer Answer Answer

Title V Question V Answer Answer Answer

Sunny Dhillon
  • 81
  • 1
  • 1
  • 8
  • Possible duplicate of [How to add Three Level ListView in ExpandableListView in android](http://stackoverflow.com/questions/32880281/how-to-add-three-level-listview-in-expandablelistview-in-android) – AL. Jun 06 '16 at 06:45

1 Answers1

0

Was implementing such thing, was using AnimatedExpandableListView was done with one adapter that recreates itself recursively.

you need data:

private HashMap<CategoryModel, List<CategoryModel>> mMainMenuExpandableList; // this is hashmap for categories;

this is your constructor for adapter:

public CategoriesExpandableListAdapter(Context context, HashMap<CategoryModel, List<CategoryModel>> hashMap, int parentCategoryId, int paddingLevel){ //... parent category is category from which start adapter (you search for it and init adapter according it, padding level i used to make padding from left for sub categories)

okay now:

you need 2 views for sub categories one is final that has no sub categories and another is one that contains also AnimatedExpandableListView which you init with created another adapter for it in on create view holder. I was set this list visibility to gone, and display it only when user tapped on it, with custom dropdown animation applied.

here is sample of item with expandable list:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_container"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:focusable="false"
    android:clickable="true"
    android:background="@drawable/custom_background"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/item_layout"
        android:layout_width="match_parent"
        android:focusable="false"

        android:layout_height="wrap_content">
        <com..........customModels.TextViewMedium
            android:id="@+id/categoryTitle"
            android:focusable="false"
            android:layout_gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:gravity="center_vertical"
            android:layout_marginRight="48dp"
            android:textSize="18dp"
            android:text="test text"/>
    </LinearLayout>
    <ImageView
        android:id="@+id/item_folder_icon"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_marginLeft="4dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_folder"/>
    <ImageView
        android:id="@+id/item_folder_right_arrow"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_rightarow"/>
    <View
        android:id="@+id/item_divider"
        android:layout_below="@id/item_layout"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/divider"/>
    <LinearLayout
        android:layout_below="@+id/item_divider"
        android:id="@+id/main_menu_expandable_sublist_container"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:visibility="gone"
        android:layout_height="wrap_content">
        <com..........customModels.AnimatedExpandableListView
            android:id="@+id/main_menu_expandable_sublist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@color/divider"
            android:childDivider="@color/divider"
            android:transcriptMode="normal"
            android:visibility="gone"
            android:groupIndicator="@null"
            android:background="@color/layouts_background"/>
    </LinearLayout>

</RelativeLayout>

here is sample of final item (without subcats):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_container"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:focusable="false"
    android:clickable="true"
    android:background="@drawable/custom_background"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/item_folder_right_arrow"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_rightarow"/>
    <LinearLayout
        android:id="@+id/item_layout"
        android:layout_width="match_parent"
        android:focusable="false"

        android:layout_height="match_parent">
        <com...........customModels.TextViewMedium
            android:id="@+id/categoryTitle"
            android:focusable="false"
            android:layout_gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:gravity="center_vertical"
            android:layout_marginRight="48dp"
            android:textSize="18dp"
            android:text="test text"/>
    </LinearLayout>
    <View
        android:layout_below="@id/item_layout"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/divider"/>
</RelativeLayout>

it's not easy to implement but final result works like a charm ))

Stepan Maksymov
  • 2,618
  • 19
  • 31