i'm developing a simple quiz in my android project, and i create 15 sample question. i want to random that questions, but i don't know how to write the code. help me please!! and thanks for your time. Here is my code
package com.adm.kana;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
public class Kuis_Hiragana extends Activity implements View.OnClickListener {
TextView pertanyaan, salahbenar;
Button jawab, lanjut;
EditText jawaban;
int benar=0, salah=0, index=0;
String[] soal={"ぐ ","く ","あ ","ば ","き ゅ ","ち ょ ","ち ","お ","ぽ ","ね ","わ ","む ","れ ","ぞ ","し ょ "};
String[] jawabann={"gu","ku","a","ba","kyu","cho","chi","o","po","ne","wa","mu","re","zo","sho"};
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.kuis);
salahbenar=(TextView)findViewById(R.id.salahbenar); salahbenar.setText("");
pertanyaan=(TextView)findViewById(R.id.soal); pertanyaan.setText(soal[0]);
lanjut=(Button)findViewById(R.id.lanjut_soal); lanjut.setOnClickListener(this);
jawab=(Button)findViewById(R.id.btn_jawab); jawab.setOnClickListener(this);
}
@Override
public void onClick(View v) {
salahbenar=(TextView)findViewById(R.id.salahbenar);
jawaban=(EditText)findViewById(R.id.jawab);
if (v==jawab){
String jawab1=jawaban.getText().toString();
if (jawab1.equalsIgnoreCase(jawabann[index]))
{ salahbenar.setText("BENAR"); benar++; }
else
{ salahbenar.setText("SALAH"); salah++;}
}
else if (v==lanjut){
if (index<soal.length-1){
index++;
pertanyaan.setText(soal[index]);
jawab.setEnabled(true);
lanjut.setVisibility(View.VISIBLE);
jawaban.setText("");
salahbenar.setText("");
}
else {
Intent i = new Intent(Kuis_Hiragana.this, Hasil.class);
i.putExtra("BENAR", benar);
i.putExtra("SALAH", salah);
startActivity(i);
onStop(); System.exit(0);
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire