To iterate in the above database, try this:-
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Categories");
ref.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnasphot datas: dataSnasphot.getChildren()){
String num=datas.child("1").getValue().toString();
String twos=datas.child("2").getValue().toString();
String threes=datas.child("3").getValue().toString();
String four=datas.child("4").getValue().toString();
//so on
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
Using the for loop, then you will be able to iterate inside Barbs
and Tetras
, and get the values of the attributes insides them(values of 1,2,3,4,5,6..)
for a button:
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getBaseContext(), FishInfo.class);
intent.putExtra("typeName", num);
intent.putExtra("typeInfo", twos);
startActivity(intent);
finish();
}
});