My query is that my Values are stored in HashMap<Integer, Object> which are stored in ArrayList. I am able to inflate it however it only gets inflate the last value added.
There are 7 items based on user location and it can differ from location to location. The seven items are (A,B,C,D,E,F,G)
I am trying to test whether it prints all the seven-item or not. But it only prints the "G" since its added in the HashMap at the end. However, all the values are stored in the Arraylist
Here is the Code I for onBindViewHolder & getItemCount
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ProductList data;
int n=0;
for (HashMap<Integer, Object> mapEntry: itemDataList){
//mapEntery shows size: 3 and
//itemDataList shows size: 7 IDK Why there is a mismatch also.
//Size of itemDataList is accurate which is why its prints 7 times
data = (ProductList) mapEntry.get(n)
System.out.println(data);
holder.recyclerViewItemNameAdapter.setText(data.getITEM_NAME());
n++;
}
}
@Override
public int getItemCount() {
return itemDataList.size();
}
MyMainActivity:
ValueEventListener eventListener= new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
int n=0;
for (DataSnapshot ds: dataSnapshot.getChildren()){
for (int i=0; i<LocateUID.size();i++){
String uid= LpcateUID.get(i);
String dsUID= ds.getKey();
final HashMap<Integer, Object> id = new HashMap<>();
if(dsUID.equals(uid)){
for (DataSnapshot d: ds.getChildren()){
productList.setITEM_NAME(d.child("item_NAME").getValue(String.class));
id.put(n,productList);
arrayListProduct.add(id);
n++;
}
}
}
}
}
RecyclerItemList();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
};
It only prints the last value stored for the length of an ArrayList.
Can anyone help me out how can I resolve this issue.