嗨,我是编程新手,我想将我的firebase数据库中的数据显示到textview中。 我写了一些代码,但我没有工作。 我希望你能帮助我
谢谢
这是我的代码
public void goToAnotherActivity19(View view) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
assert user != null;
final String log_uid = user.getUid();
final String Eintrag = eintragTagebuch.getText().toString().trim();
Intent Intent = new Intent(this, Tagebuch.class);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("User" + log_uid);
myRef.child("Tagebuch").push().setValue("Ihr Eintrag: " + Eintrag );
startActivity(Intent);
eingabeAusgeben();
}
public void eingabeAusgeben() {
tagebuchText = (TextView) findViewById(R.id.tagebuch_text2);
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
assert user != null;
final String log_uid = user.getUid();
DatabaseReference tagebuchRef = rootRef.child("User"+log_uid).child("Tagebuch");
ValueEventListener eventListener = new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String value = ds.getValue(String.class);
Log.e("TAG", value + ", ");
tagebuchText.setText("Deine Einträge" + value);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
tagebuchRef.addListenerForSingleValueEvent(eventListener);
}