Is there a way I can set a RadioButton
with a string value in my Firebase Realtime Database? Is it possible? Below is my code.
DatabaseReference questions_beg_java = FirebaseDatabase.getInstance().getReference().child("Questions").child("BeginnerJava").child("QuestionOne");
questions_beg_java.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String question_one = dataSnapshot.child("question_one").getValue().toString();
String answer_one = dataSnapshot.child("answer_one").getValue().toString();
String answer_two = dataSnapshot.child("answer_two").getValue().toString();
String answer_three = dataSnapshot.child("answer_three").getValue().toString();
//radioButton1.
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
What do I add to set a value to the RadioButton
? As in retrieving it from Firebase Realtime Database?
The Android RadioButton
widget is basically a TextView
with some extra styling and functionality. It is therefore inheriting all methods from TextView
, including setText()
.
This means that you can do something like:
String answer_one = dataSnapshot.child("answer_one").getValue().toString();
radioButton1.setText(answer_one);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.