首页 > 解决方案 > 从 Firebase 数据库到 Android 的单选按钮数据检索

问题描述

我正在尝试将用户名检索到个人资料活动中,并且我根据用户的性别对用户进行了分类。请告诉我如何从Firebase数据库的单选按钮子项中检索用户名。下面是我的代码片段。

mRadioGroup = (RadioGroup) findViewById(R.id.radiogroup);
int selectId = mRadioGroup.getCheckedRadioButtonId();

final RadioButton radioButton = (RadioButton) findViewById(selectId);

if (radioButton.getText() == null) {
    return;
}
mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(radioButton.getText().toString()).child(current_uid);

标签: androidfirebasefirebase-realtime-database

解决方案


你可以这样 -

mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users")
.child(radioButton.getText().toString()).child(current_uid)
.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot){
        // The rest code after retrieval of a user goes here

    }

推荐阅读