How to get text
in TextView
from RealTime
Database using Java?
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! } } });