Question

I have a custom ListView with following layout :

    <?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"
              android:layout_gravity="center"
        >
    <TextView
            android:id="@+id/question"
            android:padding="5dip"
            android:background="#e0f3ff"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    <LinearLayout
            android:id="@+id/panel"
            android:visibility="gone"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        <TextView
                android:layout_margin="2dip"
                android:id="@+id/answer"
                android:padding="5dip"
                android:background="#FFFFFF"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

so my view is like :

 1. Q
    A
 2. Q
    A
 3. Q
    A

Now I want to bind click event in each 'Q' and according to that I want to change visibility of 'A'.Also I want reference for each question,answer and answer wrapper layout.I am using custom adapter 'helpAdapter'.

1.How can get reference of each question ?
2.How can I get reference like id or something else(unique) of each answer ?
3.How can I get reference of each Linear layout(wrapper of answer(A)) ?
4.How can I bind click event only in Question(Q) ?
Was it helpful?

Solution

use ExpandableListView in your xml.set each group to Question(Q) and item group to answer(A) this automatically show and hide child item when click on Q;

OTHER TIPS

Inside your list adapter, in the getView() method you can set anonClickListener to the question TextView. Then in the onClickListener you change the visibility of the answer (possibly with some kind of animation).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top