这是我的firebase数据库,我想在ListView
点击此处查看所有大学名称点击此处查看图片
myRef= FirebaseDatabase.getInstance().getReference();
myRef.child("Universities").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
database c = postSnapshot.getValue(database.class);
final String name = c.getuniName();
userNameList.add(name);
final ArrayAdapter<String> mutahirAdapter=new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1 , userNameList);
mListView.setAdapter(mutahirAdapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
数据库类
我直接在Firebase中添加了数据我现在无法获取ListView
中的数据我想要检索ListView
package com.mutahir.futureguide;
public class database {
String Name;
public String uniName(String Name) {
this.Name= Name;
return Name;
}
public String getuniName() {
return Name;
}
public void setuniName(String Name) {
this.Name = Name;
}
}
答案 0 :(得分:2)
希望它有效!
myRef= FirebaseDatabase.getInstance().getReference();
myRef.child("Universities").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
final String name = postSnapshot.getValue("name").toString();
userNameList.add(name);
}
if(!userNameList.isEmpty()){
final ArrayAdapter<String> mutahirAdapter=new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1 , userNameList);
mListView.setAdapter(mutahirAdapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});