Randomising placement of Buttons
<p>I have a simple quiz game which is working well but the one problem I am having is that the answer and options to the questions are displayed on buttons but the answer button appears in the same place everytime. </p>

<p>Is there a way to randomise the positioning through the XML interface or would it be better to handle this on the coding side?</p>

<p>Below is the code I am using for the XML and the code I use to bind the data value from SQLite to the buttons. Any advice would be much appreciated.</p>

<pre><code>private void showQuestions(Cursor cursor) {
// Collect String Values from Query
StringBuilder questiontxt = new StringBuilder("");
StringBuilder answertxt1 = new StringBuilder("");
StringBuilder answertxt2 = new StringBuilder("");
StringBuilder answertxt3 = new StringBuilder("");
StringBuilder answertxt4 = new StringBuilder("");

while (cursor.moveToNext()) {
String question = cursor.getString(2);
String answer = cursor.getString(3);
String option1 = cursor.getString(4);
String option2 = cursor.getString(5);
String option3 = cursor.getString(6);
questiontxt.append(question).append("");
answertxt1.append(answer).append("");
answertxt2.append(option1).append("");
answertxt3.append(option2).append("");
answertxt4.append(option3).append("");
}
// Display answer button
TextView answer = (TextView) findViewById(R.id.option1_button);
answer.setText(answertxt1);
//Display question
TextView text = (TextView) findViewById(R.id.text);
text.setText(questiontxt);
TextView optionbutton1 = (TextView) findViewById(R.id.option2_button);
optionbutton1.setText(answertxt2);
TextView optionbutton2 = (TextView) findViewById(R.id.option3_button);
optionbutton2.setText(answertxt3);
TextView optionbutton3 = (TextView) findViewById(R.id.option4_button);
optionbutton3.setText(answertxt4);
}
</code></pre>

<p>And the XML</p>

<pre><code>&lt;Button
android:id="@+id/option1_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/option3_button"/&gt;

&lt;Button
android:id="@+id/option2_button"
android:text="@string/option2_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@+id/option4_button"/&gt;

&lt;Button
android:id="@+id/option3_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/option3_label"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/&gt;

&lt;Button
android:id="@+id/option4_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/option4_label"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/&gt;
</code></pre>
