I am trying to retrieve a HashMap from Firebase to populate my Firebase RecyclerView
below is my model class that I am trying to retrieve:
public class Employee{
private HashMap<String, Person> PeopleMap;
// = new HashMap<String, Person>();
public Employee () {
}
public Employee(HashMap<String, Person> people) {
this.PeopleMap= people;
}
public HashMap<String, Person> getMap() {
return PeopleMap;
}
public void setMap(HashMap<String, Person> people) {
this.PeopleMap= people;
}
}
Person class
public class Person {
private String ImageUrl;
private String Name;
private String Pay;
public Person() {
}
public Person(String name, String imageUrl, String pay,
) {
ImageUrl = imageUrl;
Name = name;
Pay = pay;
}
public String getImageUrl() {
return ImageUrl;
}
public void setImageUrl(String imageUrl) {
ImageUrl = imageUrl;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getPay() {
return Pay;
}
public void setPrice(String pay) {
Pay= pay;
}
}
Now the problem is that when i retrieve my Employe model class in firebase recycler it is not null but if i retrieve my Hashmap from there the size of map is zero while there are items on the map below is what i am doing
Firebase REycler
@Override
protected void onBindViewHolder( ConvoViewHolder holder, int
position, Employee model) {
if (model.equals(null)){
Toast.makeText(OrderConversation.this, "object is null",
Toast.LENGTH_SHORT).show();
}
else
{
HashMap<String, OrderItem> cartitems = model.getCart();
int i = cartitems.size();
if (i==0)
{
Toast.makeText(OrderConversation.this, "null
map", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(OrderConversation.this, "size of
map in bind"+ Integer.toString(i),
Toast.LENGTH_SHORT).show();
}
}
}
};
mEmpList.setAdapter(adapter);
adapter.startListening();
My Database structure is like below with employee as a parent node and
Sorry I had to type it i hope it is clear to everyone about what kind of str i have. i want to retrieve from department node so that i can get two object (DHead1 & Dhead2 ), which have different no of elements in them as Dhead has 3 objects of person class and Dhead2 has 2. so one way i can go is either i load them first into a list and them use them or the other way that i am using now i.e. retrieve them as an object which contains the map of person class object.
i tried this below and i am getting values fine but inside onbindview its not working
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()){
GenericTypeIndicator<Map<String, Person>> to = new
GenericTypeIndicator<Map<String, Person>>() {};
Map<String, Person> map = ds.getValue(to);
for(Person ml:convoModels.values()) {
String name = ml.getName();
Toast.makeText(context, "name is "+ name,
Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});