I am trying to pull inventory data and in the end display it on a listview with using an array adapter. Basically I need to add each item object to list then with itemobject.getName() I need to access itemname.
Users
UserID
inventory
0
name:coffee
count:1
1
name:testitem
count:2
Item Class:
public class Item {
private String name;
private int count;
public Item(){
}
public String getName(){
return name;
}
public int getCount(){
return count;
}
}
This is how I take data:
inventoryview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mydb.child("users").child(uid).child("inventory").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String data = dataSnapshot.getValue().toString();
Log.d("asd",data);
Item item = dataSnapshot.getValue(Item.class);
//iterate through incoming data and add item objects to list
Log.d("itemname",item.getName());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Toast.makeText(getActivity(),
"Inventory clicked.",
Toast.LENGTH_LONG).show();
}
});