urksiful

Add Count On Item Viewed

Jun 20th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. DatabaseReference refCount;
  2. DataSnapshot datCount;
  3.  
  4. public void initCountFoodInstances(){
  5.     refCount = data.getReference("contador");
  6. refCount.addValueEventListener(new ValueEventListener() {
  7.             @Override
  8.             public void onDataChange(DataSnapshot ds) {
  9.                 datCount = ds;    
  10.             }
  11.  
  12.             @Override
  13.             public void onCancelled(DatabaseError de) {
  14.                 System.out.println("Error");
  15.             }
  16.  
  17.         });
  18. }
  19.  
  20. public void addCountFood(){
  21.      int size = Integer.parseInt(datCount.getValue(String.class));
  22.      refCount.setValue((size+1)+"");
  23. }
Add Comment
Please, Sign In to add comment