Skip to content
Advertisement

How to get “Text” in TextView from RealTime Firebase

How to get text in TextView from RealTime Database using Java?

screenshot

Advertisement

Answer

To get the value of “text” field that exists under your “app_billing” node, please use the following lines of code:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference textRef = rootRef.child("app_billing").child("text");
textRef.get().addOnCompleteListener(new OnCompleteListener<DataSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<DataSnapshot> task) {
        if (task.isSuccessful()) {
            DataSnapshot snapshot = task.getResult();
            String text = snapshot.getValue(String.class);
            textView.setText(text);
        } else {
            Log.d("TAG", task.getException().getMessage()); //Don't ignore potential errors!
        }
    }
});
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement