我的数据库参考:
DatabaseReference mReference = FirebaseDatabase.getInstance()。getReference();
在Android应用程序中,我想要的只是检索子节点(“红色”节点)。如果可能的话,我不想找回其内在的孩子。
这是我的代码:
private ListView userList;
private ArrayList<String> usernames = new ArrayList<>();
private ArrayList<String> keys = new ArrayList<>();
private DatabaseReference mDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userList = (ListView) findViewById(R.id.usernames);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames);
userList.setAdapter(arrayAdapter);
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
for(DataSnapshot childNodes : dataSnapshot.getChildren()) {
usernames.add(childNodes.getValue(String.class));
arrayAdapter.notifyDataSetChanged();
}
}
}
}
我只想在android listview中列出节点名称,无论是否检索所有子节点。有什么办法吗? 我尝试了'getChildren()'方法,但它检索所有子节点(lat,long)但不检索bus_01,bus_02和bus_03。任何帮助?