I need to get all the data from the firebase and create a list, so I can use it in a listadaper
that I created.
This is the Bank's structure in Firebase:
Asyoucansee,Iwanttogetallthechild
Wallpapers(wallpaper1,wallpaper2,etc).
Ihavethefollowingcode:
DatabaseReferenceref=FirebaseDatabase.getInstance().getReference().child("Wallpapers").child("Wallpaper1");
And no value listener:
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<Wallpaper> list = new ArrayList<>();
String Nome = (String) dataSnapshot.child("Nome").getValue();
String Descricao = (String) dataSnapshot.child("Descricao").getValue();
String URL = (String) dataSnapshot.child("URL").getValue();
Wallpaper wallpaper = new Wallpaper(Nome, URL, Descricao);
list.add(wallpaper);
List_Adapter adapter = new List_Adapter(getApplicationContext(), list);
lista_principal.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
ref.addListenerForSingleValueEvent(eventListener);
}
But as it's kind of obvious, you're just getting the items from Wallpaper1; What I need is to get all Wallpapers items and add them to a List of this class:
public class Wallpaper {
private String Nome;
private String Url;
private String Descricao;
public Wallpaper(String nome, String url, String descricao) {
Nome = nome;
Url = url;
Descricao = descricao;
}
So I can use it in the Listview adapter I created.