user3673818
user3673818

Reputation: 23

Implementing expandable list using array adapter

I am trying to implement a premade library downloaded from a site to use it in my listview. It's called expandable listview, and I think we all know what that is.

In the XML file listview is like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical">
<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/text"
            android:text="Hello World"/>

    <!-- this is the button that will trigger sliding of the expandable view -->
    <Button
            android:id="@+id/expandable_toggle_button"
            android:text="More"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/text"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@id/text"/>

</RelativeLayout>

<!-- this is the expandable view that is initially hidden and will slide out when the 
more button is pressed -->
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:id="@+id/expandable"
        android:background="#000000">

    <!-- put whatever you want in the expandable view -->
    <Button
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:text="Action A" />

    <Button
            android:id="@+id/details"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="0.5"
            android:text="Action B"/>

</LinearLayout>
</LinearLayout>

As we all know, an array list needs the listview to be just textview to work, otherwise it throws exception.

Can some one guide me how these things work on array list?

Upvotes: 0

Views: 127

Answers (1)

KaHeL
KaHeL

Reputation: 4371

You can use custom adapter for this. See this link for tutorial on how to. :)

Upvotes: 1

Related Questions