private void GetAnswers(Integer _id) { openDatabaseConnection(); String WhereStatement = "QUESTIONITEM " + "= " + String.valueOf(_id); String[] Columns = {"CORRECT", "ANSWERTEXT", "REASON"}; Cursor c = myDbHelper.query("ANSWERS", Columns, WhereStatement, null, null, null, null); if (c.getCount() > 0) { c.moveToFirst(); List<Answer> list = new ArrayList<Answer>(); CorrectAnswerList = new ArrayList<Answer>(); CorrectAnswerInHTMLList = new ArrayList<String>(); do { Answer ans = new Answer(); ans.set_Correct(c.getInt(c.getColumnIndex("CORRECT"))); ans.set_AnswerText(c.getString(c.getColumnIndex("ANSWERTEXT"))); ans.set_Reason(c.getString(c.getColumnIndex("REASON"))); list.add(ans); // if the answer is correct keep the string in HTML if (ans.get_Correct() == 1) { String CorrectAnswerInHTML = ans.get_AnswerText(); CorrectAnswerReasonInHTML = ans.get_Reason(); CorrectAnswerList.add(ans); // Collection of correct answers CorrectAnswerInHTMLList.add(CorrectAnswerInHTML); CorrectAnswerInHTMLListCounter++; } } while (c.moveToNext()); c.close(); myDbHelper.close(); // Add the number of Answer to the CorrectAnswerListCounter CorrectAnswerListCounter = CorrectAnswerList.size(); // Initialize button array ButtonArray = new ArrayList<Button>(); for (int current = 0; current < list.size(); current++) { Answer ThisAns = list.get(current); // Create a table row TableRow tr = new TableRow(this); tr.setId(1000 + current); tr.setGravity(Gravity.CENTER); tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); /*TextView Tv = new TextView(this); Tv.setId(1000+current); Tv.setText(Html.fromHtml(ThisAns.get_AnswerText())); Tv.setTextColor(Color.WHITE); tr.addView(Tv); Table.addView(tr);*/ // Configure each button and add to row and then add row to table Button bt = new Button(this); bt.setId(1000 + current); bt.setText(Html.fromHtml(ThisAns.get_AnswerText())); bt.setTextColor(Color.BLACK); bt.setGravity(Gravity.CENTER); bt.setWidth(420); bt.setHeight(LayoutParams.WRAP_CONTENT); bt.setTextSize(12); // Add the correct answer to the button bt.setTag(ThisAns.get_Correct()); bt.setOnClickListener(this); // Add button the button array ButtonArray.add(bt); tr.addView(bt); Table.addView(tr); } } }