This is not an exact solution to your problem of receiving data from firebase in the reverse order, but in any case, we have other problems.
The first work around is mentioned in the comment on using a custom adapter for your list.
To achieve this behavior, you need to get the database data in the list, and then you must cancel it yourself before transferring it to the adapter. Just!
The second job is as easy as pie, and I think that if you use RecyclerView , this can do the trick for you, and I believe that this is the easiest way to get the job done.
Here I am changing part of my code using RecyclerView
// Declare the RecyclerView and the LinearLayoutManager first private RecyclerView listView; private LinearLayoutManager mLayoutManager;
...
@Override public void onViewCreated(View view, Bundle savedInstanceState){
By setting mLayoutManager.setReverseLayout(true); - you change the layout, and mLayoutManager.setStackFromEnd(true); Positions the view at the top of the list.
Switching to RecyclerView is simple. Your layout will be something like this.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"> <android.support.v7.widget.RecyclerView android:id="@+id/my_list" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
And in your build.gradle
dependencies { compile 'com.android.support:recyclerview-v7:23.4.0' }
You need the FirebaseRecyclerAdapter be found here in the FirebaseUI library.
Note. Do not use RecyclerView.LayoutManager , as the setReverseLayout and setStackFromEnd functions will not be found in RecyclerView.LayoutManager . Use LinearLayoutManager as LinearLayoutManager .
Update
Here you can handle click events of your items in the list.
Did you need to declare a ViewHolder for the correct implementation of RecyclerView ? Just add another function to your ViewHolder class, as shown below, and call this function after the setText functions that you have.
public static class MyViewHolder extends RecyclerView.ViewHolder { View mView; public MyViewHolder(View itemView) { super(itemView); mView = itemView; } public void setClickEvent() {