How to display multiple number of TextViews inside each row in ListView?

Viewed 15127

I am creating a Help page in which I have a set of questions and answers. These questions and answers have different styles. Here is the xml file, which describes the layout of a question & answer set:

<?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:text="@string/Help_first_question"
            android:id="@+id/text1"
            android:padding="5dip"
            android:background="#e0f3ff"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    <LinearLayout
            android:id="@+id/panel1"
            android:visibility="gone"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        <TextView
                android:layout_margin="2dip"
                android:text="@string/Help_first_answer"
                android:padding="5dip"
                android:background="#FFFFFF"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

I want to display multiple questions and answers within a listView, whereby each row contains a set of the question and the answer. My listview looks like :

    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/listview"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" >  
    </ListView>

so it will look like :

first row  :  Q
              A
second row :  Q
              A
third row  :  Q
              A 

What is the best approach for achieving this?

2 Answers
Related