Display new items at the top of a ListView

前端 未结 8 848
北恋
北恋 2021-01-02 06:28

I\'m using a list to populate a ListView (). The user is able to add items to the list. However, I need the items to be displayed at the top of the ListView. How do I insert

8条回答
  •  盖世英雄少女心
    2021-01-02 06:54

    The ListView displays the data as it is stored in your data source.

    When you are adding in your database, it must be adding the elements in the end. So, when you are getting all the data via the Cursor object and assigning it to the ArrayAdapter, it is in that order only. You should basically be trying to put data in the beginning of the database, rather that in the end, by having some time-stamp maybe.

    Using ArrayList, you can do it by Collections.reverse(arrayList) or if you are using SQLite, you can use order by.

提交回复
热议问题