inferKNOX inferKNOX - 26 days ago 7
Android Question

Expandable table view

Is it possible to make an expandable table in Android, that is similar to the expandable list view, but where the child items are in a table/grid format.
For example, something like is here: http://www.coderzheaven.com/2011/04/10/expandable-listview-in-android-using-simpleexpandablelistadapter-a-simple-example/
, but with the child items being a grid of images.

This is how far I've gotten so far (in activity_main.xml using Eclipse Kepler) and am stuck on:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<ExpandableListView
android:id="@+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ExpandableListView>

<ExpandableListView
android:id="@+id/expandableListView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ExpandableListView>

<ExpandableListView
android:id="@+id/expandableListView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ExpandableListView>

</LinearLayout>

Answer

With your expandable list view with usage of ExpandableListAdapter you can make your child cells to be TableViews or GridViews or whatever you want inside.

Just inflate view which you want in:

@Override
public View getChildView(int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this.context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.your_item_with_grid, null);
    }

    // get your views from convert view here

    return convertView;
}

Here you got ExpandableListAdapter tutorial