I am teacher and creating a quiz for my students rest is complete I have 500 questions on my firebase real time database all I want to do is randomize questions each time 50 questions and set a listener after 50 questions here my quiz activity
public class grandtest extends AppCompatActivity {
TextView mQuestionTextView;
ProgressBar mProgressBar;
Button bchoice1,bchoice2,bchoice3,bchoice4;
Random Rand;
String mAnswer;
Timer mTimer;
TextView mScoreTextView;
public static int mScore;
int mQuestionNo = 0;
private Firebase mQuestionRef;
private Firebase mChoice1Ref;
private Firebase mChoice2Ref;
private Firebase mChoice3Ref;
private Firebase mChoice4Ref;
private Firebase mAnswerRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grandtest);
mQuestionTextView = findViewById(R.id.mquestiontextview);
mProgressBar = findViewById(R.id.progressBar);
bchoice1 = findViewById(R.id.choice1);
bchoice2 = findViewById(R.id.choice2);
bchoice3 = findViewById(R.id.choice3);
bchoice4 = findViewById(R.id.choice4);
mScoreTextView = findViewById(R.id.mScore);
}
public void updateQuestion (){
mQuestionRef = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo +"/question");
mQuestionRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String question = dataSnapshot.getValue(String.class);
mQuestionTextView.setText(question);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(grandtest.this,"Please enable data",Toast.LENGTH_SHORT).show();
}
});
mChoice1Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice1");
mChoice1Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice1 = dataSnapshot.getValue(String.class);
bchoice1.setText(choice1);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
mChoice2Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice2");
mChoice2Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice2 = dataSnapshot.getValue(String.class);
bchoice2.setText(choice2);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
mChoice3Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice3");
mChoice3Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice3 = dataSnapshot.getValue(String.class);
bchoice3.setText(choice3);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
mChoice4Ref = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/choice4");
mChoice4Ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String choice4 = dataSnapshot.getValue(String.class);
bchoice4.setText(choice4);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
mAnswerRef = new Firebase("https://class9notes-2808b.firebaseio.com/"+mQuestionNo+"/answer");
mAnswerRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mAnswer = (String) dataSnapshot.getValue(String.class);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
mQuestionNo ++;
I want to randomize mQuestionNo object to retrieve random questions each time. Here is structure of my firebfarebase dataase data
Aucun commentaire:
Enregistrer un commentaire