I am using Android Studio. I want show "correct" or "incorrect" using Toast
in my app for the answers. How to show Toast
messages? Below is my code:
public class LayarKuisUmumNo1 extends Activity {
Button bt;
TextView tv;
RadioGroup rg;
RadioButton rbu1, rbu2, rbu3, rbu4;
public static String question[] = { "Negara terluas keempat di dunia"};
String answer[] = { "Amerika"};
String opts[] = { "Rusia", "Australia", "Amerika", "Indonesia" };
int position = 0;
public static int correct;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layar_kuis_umum_no1);
bt = (Button) findViewById(R.id.btnextu1);
tv = (TextView) findViewById(R.id.pertanyaanu1);
rg = (RadioGroup) findViewById(R.id.radioGroup2);
rbu1 = (RadioButton) findViewById(R.id.rbu1a);
rbu2 = (RadioButton) findViewById(R.id.rbu1b);
rbu3 = (RadioButton) findViewById(R.id.rbu1c);
rbu4 = (RadioButton) findViewById(R.id.rbu1d);
tv.setText(question[position]);
rbu1.setText(opts[position]);
rbu2.setText(opts[position + 1]);
rbu3.setText(opts[position + 2]);
rbu4.setText(opts[position + 3]);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioButton selectedans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
String selectedanstext = selectedans.getText().toString();
if (selectedanstext == answer[position]) {
correct++;
}
position++;
if (position < question.length) {
tv.setText(question[position]);
rbu1.setText(opts[position * 4]);
rbu2.setText(opts[position * 4 + 1]);
rbu3.setText(opts[position * 4 + 2]);
rbu4.setText(opts[position * 4 + 3]);
} else {
Intent in = new Intent(getApplicationContext(), LayarNilaiUmum1.class);
startActivity(in);
}
}
});
}
}