Skip to content

Instantly share code, notes, and snippets.

@mozerian
Created July 17, 2020 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mozerian/4533361d40268fe469442e2f1bfdd798 to your computer and use it in GitHub Desktop.
Save mozerian/4533361d40268fe469442e2f1bfdd798 to your computer and use it in GitHub Desktop.
//function to fetch payment data from the database
private void fetchPaymentUsers()
{
payRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
//creating an object and setting to displlay
Constants pays = new Constants();
pays.setFirst_Name(snapshot.child("FirstName").getValue().toString());
pays.setOther_Name(snapshot.child("OtherName").getValue().toString());
pays.setPhone(snapshot.child("Phone").getValue().toString());
//this just log details fetched from db(you can use Timber for logging
Log.d("Payment", "Name: " + pays.getFirst_Name());
Log.d("Payment", "othername: " + pays.getOther_Name());
Log.d("Payment", "phone: " + pays.getPhone());
/* The error before was cause by giving incorrect data type
You were adding an object of type PaymentUsers yet the arraylist expects obejct of type DisabledUsers
*/
paymentUsersList.add(pays);
}
//create a pdf file and catch exception beacause file may not be created
try {
createPaymentReport(paymentUsersList);
} catch (DocumentException | FileNotFoundException e) {
e.printStackTrace();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment