android - 从 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);
解决方案
你可以这样 -
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
}
推荐阅读
- python - Python OLAP 框架多维数据集
- c++ - 即使引用计数不为零,如何处理动态加载的DLL也可以被Windows卸载?
- windows - 如何禁用请求允许在您的设备上进行更改的窗口
- javascript - 如何对新员工的注册表进行密码保护
- json - How to insert date from JSON to SQL database
- android - 管理 Firebase 安装实施的截止日期是什么时候?移动应用中已弃用的 Firebase 安装 ID 有什么影响?
- java - 在 Spring Boot 应用程序中更新底层依赖 bean 时刷新 bean
- excel - Office 加载项:在 Excel 加载项中创建 Word 文档或文本文件
- python - 失败的 test_main.py::test_login_success - tortoise.exceptions.ConfigurationError:没有与模型关联的数据库
- c# - 从多个文本框中获取文本