Reputation: 21
I have a local json file that stores questions
("Questions ": [
{
"question": ".........",
"answer1": ".......",
"answer2": " ......",
"answer3": ".......",
"correctAnswer: "........"
},
{
"question": ".........",
"answer1": ".......",
"answer2": " ......",
"answer3": ".......",
"correctAnswer: "........"
})
I created the xml layout that take the data and store it onto it. When a user selects submit answer, I want to be able to display a dialog box stating if answer selected was correct/incorrect along with the correct answer displayed(corrrectAnswer). How to do this?
//xml layout quiz
Question(TextView
Ans1 Ans2 (radioButtons) Ans3
Submit answer
(Button)
Upvotes: 2
Views: 59
Reputation: 942
AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this);
// 2. Chain together various setter methods to set the dialog characteristics
builder.setTitle("Title Text").
.setMessage(*String comprised of your desired notification content*)
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//for clicking OK
}
})
.show();
// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();
Upvotes: 2