How to display the textviews dynamically in a list view in android?
<p>I am working on quiz application. It contains 2 types of tests. <strong>The first test contains questions with 3 options fixed.</strong> *<em>The second test contains questions with options not fixed. i.e the options may be 4 or 5 or 6 based on the question.</em>* 
     After the test I need to display the <strong>review page.</strong> Here is the review page code for the first type of test with fixed options.(Review page should contain the questions displayed for the test at that time)  </p>

<p>My Code:</p>

<p><strong>Review.java</strong></p>

<pre><code>public class Review extends Activity {

    static ArrayList selectedoptionids = Test1.listarray;
    static ArrayList&lt;ArrayList&lt;String&gt;&gt; questionslist = Test2.stringList1;
    static ArrayList&lt;ArrayList&lt;String&gt;&gt; alloptionlist = Test2.optionstablelist;
    static ArrayList&lt;ArrayList&lt;String&gt;&gt; all = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();

    ListView list;
    Button next;
    String op1, op2, op3, op4, op5;
    ArrayList&lt;String&gt; arr1;
    ArrayList&lt;String&gt; arr2;

    int a, i;
    static int k = 0;
    static int p = 1;

    static List&lt;mainlist&gt; entirelist = new ArrayList&lt;mainlist&gt;();
    String  quest;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.review);

        list = (ListView) findViewById(R.id.listlist);

        View header = getLayoutInflater().inflate(
                R.layout.listview_header_text, null);
        list.addHeaderView(header, null, false);

        View footerView = getLayoutInflater().inflate(
                R.layout.listview_footer_text, null);
        list.addFooterView(footerView, null, false);

        next = (Button) findViewById(R.id.next);

        eachquestion();

        lvAdapter adapter = new lvAdapter(this, entirelist) {
            public boolean areAllItemsEnabled() {
                return false;
            }

            public boolean isEnabled(int position) {
                return false;
            }
        };
        list.setAdapter(adapter);
    }


    public void eachquestion() {
        arr1 = new ArrayList&lt;String&gt;();

        for (i = p - 1; i &lt; p + 3; i++) {

            arr1 = questionslist.get(i);
            arr2 = new ArrayList&lt;String&gt;();

            for (int j = 0; j &lt; 5; j++) {

                arr2 = alloptionlist.get(0);
                    if (j == 0) 
                        op1 = arr2.get(2);

                     else if (j == 1) 
                        op2 = arr2.get(2);

                     else if (j == 2) 
                        op3 = arr2.get(2);
                }

            }

    entirelist.add(new mainlist(quest, op1, op2, op3));

        }
    }

}
</code></pre>

<p><strong>mainlist.java</strong></p>

<pre><code>public class mainlist {
    String question,option1,option2,option3;

    public mainlist(String question,String option1,String option2,String option3) {
        super();
        this.question = question;
        this.option1 = option1;
        this.option2= option2;
        this.option3 = option3;
        }

    public String getquestion() {
        return question;
    }
    public void setquestion(String question) {
        this.question = question;
    }

    public String getoption1() {
        return option1;
    }
    public void setoption1(String option1) {
        this.option1 = option1;
    }

    public String getoption2() {
        return option2;
    }
    public void setoption2(String option2) {
        this.option2 = option2;
    }

    public String getoption3() {
        return option3;
    }
    public void setoption3(String option3) {
        this.option3 = option3;
    }
}
</code></pre>

<p><strong>lvAdapter.java</strong></p>

<pre><code>public class lvAdapter extends BaseAdapter implements OnClickListener {
    private Context context;
     List&lt;mainlist&gt; list11 = Review.entirelist;

    public lvAdapter(Context context, List&lt;mainlist&gt; list11 ) {
        this.context = context;
        this.list11 = list11 ;
    }
    public int getCount() {
        return list11.size();
    }
    public Object getItem(int position) {
        return list11.get(position);
    }

    public long getItemId(int position) {
        return position;
    }


    public View getView(int position, View convertView, ViewGroup viewGroup) {

        mainlist inst  = list11.get(position); 

        if (convertView == null) 
        {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.reviewrow, null);
        }

        TextView question = (TextView) convertView.findViewById(R.id.textView2);
        tvPhone.setText(inst.getquestion());

        TextView option1 = (TextView) convertView.findViewById(R.id.op1);
        option1.setText(inst.getoption1());

        TextView option2 = (TextView) convertView.findViewById(R.id.op2);
        option2.setText(inst.getoption2());

        TextView option3 = (TextView) convertView.findViewById(R.id.op3);
        option3.setText(inst.getoption3());

        return convertView;
    }

    @Override
    public void onClick(View v) {

    }
}
</code></pre>

<p><strong>Now my problem is for the first test as we know the number of options are 3 so I have written the setter and getter methods for 1 question and 3 options and it is working fine.</strong> But for the second type of test how can I write the <strong>mainlist.java class</strong> for generating the setter and getter methods for unknown number of options.</p>

<p>Please help me regarding this...I am struggling for this since 3 days....</p>

<p>Thanks in advance...</p>
