I tried to receive the data from firebase using others people code but the app will be force stop. And I dont understand their code because I'm still new in android development. Here my code that only display the data in logcat but I will it display into a listview pls help me thanks.
This is xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textAlignment="center"
android:textSize="25sp"
android:text="Time Table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvUserInfo"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listview"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="11dp" />
</LinearLayout>
This is the java class:
DatabaseReference dref;
ListView listview;
ArrayList<String> list=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("Time");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String email = ds.child("email").getValue(String.class);
String time = ds.child("time").getValue(String.class);
Log.d("TAG", email + " / " + time); // logcat check value
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
usersRef.addListenerForSingleValueEvent(eventListener);
}
This picture is the firebase value that i want to display in list view (email and time)
The thing I want to do is display the data from firebase in listview
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…