I make some culinary application on android and there is any quiz within, for the question i've been able to get the text from array to text field, but for the answer i don't know how to display it to radio button. I'm new to android, please help me and thank you in advance.
cuisine1.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:src="@drawable/papeda128" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="40dp"
android:text="Papeda"
android:textColor="#000000"
android:textSize="30dp" />
</LinearLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="30dp"
android:text="Question"
android:textColor="#000000"
android:textSize="20dp" />
</LinearLayout>
</ScrollView>
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:checked="true"
android:text="Answer 1" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer 2" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer 3" />
</RadioGroup>
</LinearLayout>
cuisine1.java
package com.culinary;
import java.util.ArrayList;
import java.util.Collections;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;
public class cuisine1 extends Activity {
TextView papquest;
private int i=0;;
question q=new question();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cuisine1);
papquest=(TextView)findViewById(R.id.textView2);
String dt=q.showquestionpapeda(i);
String[] quest=dt.split("/");
papquest.setText(quest[0],null);
findViewById(R.id.radio0).setOnClickListener(mClickListener);
findViewById(R.id.radio1).setOnClickListener(mClickListener);
findViewById(R.id.radio2).setOnClickListener(mClickListener);
}
RadioGroup.OnClickListener mClickListener = new RadioGroup.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
i+=1;
String dt=q.showquestionpapeda(i);
String[] quest=dt.split("/");
papquest.setText(quest[0],null);
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
question.java
package com.culinary;
class question {
String[] papeda={
"Question 1 ?/Answer1,Answer2,Answer3",
"Question 2 ?/Answer1,Answer2,Answer3",
"Question 3 ?/Answer1,Answer2,Answer3",
"Question 4 ?/Answer1,Answer2,Answer3",
};
public void question(){
}
public String showquestionpapeda(int i){
String question;
question=papeda[i];
return question;
}
}