Android 获取保存在Firebase中的选定单选按钮的值,并将其设置为用户配置文件中的默认状态
如何将性别单选按钮设置为从数据库中选择的值,就像编辑文本按钮一样。尝试以下代码:Android 获取保存在Firebase中的选定单选按钮的值,并将其设置为用户配置文件中的默认状态,android,firebase,firebase-realtime-database,firebase-storage,Android,Firebase,Firebase Realtime Database,Firebase Storage,如何将性别单选按钮设置为从数据库中选择的值,就像编辑文本按钮一样。尝试以下代码: public void showFields(){ databaseReference = FirebaseDatabase.getInstance().getReference().child("user"); databaseReference.child(User_Login.userid).addValueEventListener(new ValueEventListener() {
public void showFields(){
databaseReference = FirebaseDatabase.getInstance().getReference().child("user");
databaseReference.child(User_Login.userid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot){
id1.setText(User_Login.userid);
name1.setText(dataSnapshot.child("name").getValue().toString());
password1.setText(dataSnapshot.child("password").getValue().toString());
mobile1.setText(dataSnapshot.child("mobile").getValue().toString());
city1.setText(dataSnapshot.child("city").getValue().toString());
area1.setText(dataSnapshot.child("area").getValue().toString());
//gender.setSelected(dataSnapshot.child("area").getValue().toString());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Where list是为性别微调器适配器设置的arraylist。试试这个
首先,您必须将性别值字符串存储到Firebase
gender.equalsIgnoreCase将检查gender的值是否等于Man(case Man),如果为true,则radiobutton male将设置为Checked(true)
我认为你可以做像这样的事情:gender.setSelected(dataSnapshot.child(“area”).getValue(Boolean.class);如果你解释一下你的答案可能会有所帮助。OP的代码有什么问题?这是如何解决的?
if (list.contains(dataSnapshot.child("gender").getValue().toString()){
int pos = list.indexOf(dataSnapshot.child("gender").getValue().toString());
gender.setSelection(pos);
}
public void showFields(){
databaseReference = FirebaseDatabase.getInstance().getReference().child("user");
databaseReference.child(User_Login.userid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot){
id1.setText(User_Login.userid);
name1.setText(dataSnapshot.child("name").getValue().toString());
password1.setText(dataSnapshot.child("password").getValue().toString());
mobile1.setText(dataSnapshot.child("mobile").getValue().toString());
city1.setText(dataSnapshot.child("city").getValue().toString());
area1.setText(dataSnapshot.child("area").getValue().toString());
String gender = dataSnapshot.child("gender").getValue().toString();
if(gender.equalsIgnoreCase("Man")){
mGenderMan.setChecked(true);
}else if(gender.equalsIgnoreCase("Woman")){
mGenderWoman.setChecked(true);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});}