我想显示(用户:....),但我不知道用户的路径。如何在列表视图中选择用户显示。请查看我的代码并帮助我
public class ListUserRoom extends AppCompatActivity {
private ListView listView;
List<Member> members = new ArrayList<>();
private DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
private String keyOfRoom = "";
private String keyOfMember = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_user_room);
createListUser();
}
private void createListUser() {
listView = (ListView)findViewById(R.id.listView);
listView.setAdapter(new ListUserRoom.ImageAdapter(this));
Intent getData = getIntent();
if(getData != null){
keyOfRoom = getData.getExtras().getString("key" , "");
}
getData = getIntent();
if(getData != null){
keyOfMember = getData.getExtras().getString("keymember" , "");
}
mDatabase = FirebaseDatabase.getInstance().getReference()
.child("AllRoom").child(keyOfRoom)
.child("Member").child(keyOfMember)
.child("User");
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Set<String> set = new HashSet<String>();
Iterator i = dataSnapshot.getChildren().iterator();
dataSnapshot.getValue();
while (i.hasNext()){
DataSnapshot data = (DataSnapshot)i.next();
Member member = data.getValue(Member.class);
member.setKey(data.getKey());
members.add(member);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
如何选择表用户:(全部)和Member.class为show listuser(私有字符串键,用户)设置模型,获取密钥用户
答案 0 :(得分:0)
您在AllRoom表
之后缺少数据库引用中的子键mDatabase = FirebaseDatabase.getInstance().getReference()
.child("AllRoom")
.child(missingKey)//You need to add a key here to be able to access Member
.child("Member");
解决之后,这里有一个我已经适应你的问题的代码
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
Member member = data.getValue(Member.class);
member.setKey(data.getKey());
Members.add(member);
}
}
希望这有帮助