Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverted ListView in Android?

Is there an easy way to display a ListView in reverse order? I am trying to create a conversation-based app, and would like the most recent entries to be at the bottom of the ListView. I am aware of transcriptMode and stackFromBottom, however my problem is the order of the data.

Say I have 100 conversation items, and want to display items 80-100, with 100 being the most recent conversation item. I would like to show 80-100, which implies an ORDER BY id desc LIMIT 20 in my query, which forces the items to be sorted 100 to 80, the opposite of what I need. I currently have some nasty inner query code, but feel like there should be a simpler solution based on reversing the cursor or simply inverting the ListView.

like image 433
bjdodson Avatar asked Jun 07 '12 23:06

bjdodson


People also ask

How do you reverse a list on Android?

To in-place reverse the order of the elements in a list, you can use the Collections. reverse() function. It takes the list whose elements are to be reversed.

What is a ListView in android?

A list view is an adapter view that does not know the details, such as type and contents, of the views it contains. Instead list view requests views on demand from a ListAdapter as needed, such as to display new views as the user scrolls up or down. In order to display items in the list, call setAdapter(android.

How do you reverse a list in DART flutter?

We can reverse a List in Dart either by using built-in functions or using looping statements with swap mechanism. Reversing a List makes the first element to be placed at last position, second element placed at last but one position and so on.


1 Answers

inside the baseAdapter, for the getView() method , instead of getting the item in the data in index "position" , use the opposite , meaning : numberOfItems minus the position .

as for showing the number of items , that's also inside the baseAdapter : set the value returned by getCount() to be the one you wish it to be (20 in your example,though 80-100 implies that it should be 21 ) .

btw, it seems you are a starter in the case of listView . may i suggest watching this video: http://www.youtube.com/watch?v=wDBM6wVEO70

also check the api-demos provided by the sdk manager . they have plenty of examples there.

like image 56
android developer Avatar answered Sep 26 '22 01:09

android developer