I'm currently making a project in which a user segregates their trash and in return, it gives them points. Using those points they can redeem awards. At the moment I'm having trouble how to display the points in Android Studio's TextView. This is my code. my database structure https://i.stack.imgur.com/TU5mM.jpg I want the points to be displayed on my TextView which is on my dashboard https://i.stack.imgur.com/9hfzb.jpg the problem occurs at the DocumentReference portion.
public class MainActivity extends AppCompatActivity {
private TextView powents;
FirebaseFirestore fStore;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button logout = findViewById(R.id.logout);
ImageView qrimage = findViewById(R.id.qrimage);
powents = findViewById(R.id.powents);
fStore = FirebaseFirestore.getInstance();
DocumentReference docref = fStore.collection("Users").document("Users");
docref.addSnapshotListener(this, (documentSnapshot, error) -> {
powents.setText(Math.toIntExact(documentSnapshot.getLong("Points")));
});
try {
BarcodeEncoder barcode = new BarcodeEncoder();
Bitmap bitmap = barcode.encodeBitmap(Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getEmail(), BarcodeFormat.QR_CODE, 650, 650);
qrimage.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
logout.setOnClickListener(view -> {
FirebaseAuth.getInstance().signOut();
Toast.makeText(MainActivity.this, "Logged Out!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(MainActivity.this, Login.class));
finish();
});
}
}