android-更改列表的排序

标签 android android-listview

我想将 ListView 的顺序更改为最近添加的项目位于 ListView 的顶部,旧的项目位于最后

我从 sqlite 获取数据,然后将它们填充到名为 reports_items_obj 的对象的数组列表中 我使用自定义adpater来查看

  ListView list_messages = (ListView) findViewById(R.id.list);

     Report_adapter adapter = new  Report_adapter(getApplicationContext(), reports_items_obj);
     list_messages.setAdapter(adapter);

 xml file 


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

         <ListView
              android:id="@+id/list"
              android:layout_height="wrap_content"
              android:layout_width="match_parent">
         </ListView>

</LinearLayout>

最佳答案

ListView 的顺序基于数组列表或游标中项目的顺序,或者来自将填充到 ListView 中的数据存储位置的顺序。所以尝试改变arraylist的顺序。

关于android-更改列表的排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25134948/

相关文章:

javascript - 移动webkit内存消耗

java - ListAdapter将数组类型改为int后拒绝申请

android - findViewById 适用于 TextView 但不适用于同级 Button

java - Android 开发字符串数组资源太大,导致 Android 应用程序崩溃!

android - 某些手机​​上的声音提前中断

android - 最佳实践 Android 包名和 IOS bundleID

java - 如何按日期和时间仅选择今天和明天的 jsonarray 数据并放入 ListView 适配器

android - 翻译动画是如何工作的 : Android

android - 来自 ArrayList 类的 ListView

java - 将数据从 edittext 发送到 listview