My database reference:
DatabaseReference mReference = FirebaseDatabase.getInstance().getReference();
In android app, what I want is to just retrieve the child nodes(the "red" ones). I don't want to retrieve its inner children if that's possible.
Here is my code:
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();
}
}
}
}
I only want to list the node names in the android listview, whether retrieving all its children or not. Is there any way? I tried 'getChildren()' method but it retrieves the all children (lat, long) but not the bus_01, bus_02 and bus_03. Any Help?