I'm making a social media app, I am sending user's posts to firebase and then I'm retrieving them in Android listView, but I am getting the newer posts at the bottom. I want my app to work just like Facebook i.e to fetch data and set them on listView according to the precedence of time (newer posts on top).
Asked
Active
Viewed 111 times
0
-
1https://stackoverflow.com/questions/9987402/is-it-possible-to-make-a-listview-populate-from-the-bottom – Efe AYDIN Aug 14 '17 at 22:51
1 Answers
0
To solve your problem, you need to add for each post in you database, a new field containing a TIMESTAMP
and then order the posts accordingly to this. To set the TIMESTAMP i recomand you using ServerValue.TIMESTAMP
and for getting the data back the following method:
public static String getTimeDate(long timeStamp){
try{
DateFormat dateFormat = getDateTimeInstance();
Date netDate = (new Date(timeStamp));
return dateFormat.format(netDate);
}
catch(Exception e){
return "date";
}
}
Hope it helps.

Alex Mamo
- 130,605
- 17
- 163
- 193
-
hey is there any way i can retrieve all the posts posted in current date? – Syyam Noor Aug 16 '17 at 15:21
-
Yes, using the solution above. Having the `TIMESTAMP` you can query your database according to it, as you want. You can use methods like startAt(), endAt(), limitToFirst() or limitToLast(). – Alex Mamo Aug 16 '17 at 15:31