i制作一个测验应用程序,其中我要显示问题,并且是无线电按钮中的四个选项,我想通过单击时将其更新为下一个ID问题,将其一个一个更新到下一个ID问题。按钮.....我应该怎么做?而且,我应该如何检查得分的分数,该分数要在下一个我将要进行的活动中显示?该应用在按钮
的列表上崩溃预先感谢!
quizactivity:
public class Quiz extends AppCompatActivity {
RadioGroup radioGroup;
RadioButton optionOne,optionTwo,optionThree,optionFour;
private TextView questionName;
String question_name;
String option1,option2,option3,option4;
Button next_question;
int first_question_index=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
questionName=(TextView)findViewById(R.id.question_name);
radioGroup =(RadioGroup)findViewById(R.id.radioGroup);
optionOne=(RadioButton)findViewById(R.id.answerOne);
optionTwo=(RadioButton)findViewById(R.id.answerOne);
optionThree=(RadioButton)findViewById(R.id.answerOne);
optionFour=(RadioButton)findViewById(R.id.answerOne);
next_question=(Button)findViewById(R.id.button_next_question);
FetchLists fetchLists =new FetchLists();
fetchLists.execute(10,0);
next_question.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
first_question_index++;
}
}); }
public class FetchLists extends AsyncTask<Integer, Void, String> {
@Override
protected String doInBackground(Integer... params) {
String urlString = "http://aptronnoida.com/Aditya_July4/Demo/JAVA_FETCH.php";
try {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
InputStream stream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line = reader.readLine();
String response = "";
while (line != null) {
response += line;
line = reader.readLine();
}
JSONObject object = new JSONObject(response);
JSONArray jsonArray = object.getJSONArray("data");
JSONObject list = (JSONObject) jsonArray.get(first_question_index);
question_name= list.getString("Question");
option1=list.getString("A1");
option2=list.getString("A2");
option3=list.getString("A3");
option4=list.getString("A4");
} catch (Exception e) {
e.printStackTrace();
}
return "quiz";
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
questionName.setText(question_name);
((RadioButton) radioGroup.getChildAt(0)).setText(option1);
((RadioButton) radioGroup.getChildAt(1)).setText(option2);
((RadioButton) radioGroup.getChildAt(2)).setText(option3);
((RadioButton) radioGroup.getChildAt(3)).setText(option4);
}
}
}
public class Quiz extends AppCompatActivity {
RadioGroup radioGroup;
RadioButton optionOne,optionTwo,optionThree,optionFour;
private TextView questionName;
String question_name;
String option1,option2,option3,option4;
Button next_question;
int first_question_index=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
questionName=(TextView)findViewById(R.id.question_name);
radioGroup =(RadioGroup)findViewById(R.id.radioGroup);
optionOne=(RadioButton)findViewById(R.id.answerOne);
optionTwo=(RadioButton)findViewById(R.id.answerOne);
optionThree=(RadioButton)findViewById(R.id.answerOne);
optionFour=(RadioButton)findViewById(R.id.answerOne);
next_question=(Button)findViewById(R.id.button_next_question);
next_question.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
first_question_index++;
FetchLists fetchLists = new FetchLists();
fetchLists.execute(10, 0);
}
});
FetchLists fetchLists = new FetchLists();
fetchLists.execute(10, 0);
}
public class FetchLists extends AsyncTask<Integer, Void, String> {
@Override
protected String doInBackground(Integer... params) {
String urlString = "http://aptronnoida.com/Aditya_July4/Demo/JAVA_FETCH.php";
try {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
InputStream stream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line = reader.readLine();
String response = "";
while (line != null) {
response += line;
line = reader.readLine();
}
JSONObject object = new JSONObject(response);
JSONArray jsonArray = object.getJSONArray("data");
JSONObject list = (JSONObject) jsonArray.get(first_question_index);
Log.d("ashu","JsonObject "+list);
question_name= list.getString("Question");
option1=list.getString("A1");
option2=list.getString("A2");
option3=list.getString("A3");
option4=list.getString("A4");
} catch (Exception e) {
e.printStackTrace();
}
return "quiz";
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
questionName.setText(question_name);
((RadioButton) radioGroup.getChildAt(0)).setText(option1);
((RadioButton) radioGroup.getChildAt(1)).setText(option2);
((RadioButton) radioGroup.getChildAt(2)).setText(option3);
((RadioButton) radioGroup.getChildAt(3)).setText(option4);
}
}
}