【问题标题】:android- change sort of listivewandroid-改变列表视图的种类
【发布时间】:2014-08-05 09:05:09
【问题描述】:

我想将 listview 的顺序更改为最近添加的项目在 listview 的顶部,旧的是最后一个

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

  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>

【问题讨论】:

标签: android android-listview


【解决方案1】:

listview 的顺序基于 arraylist 或 cursor 中的项目顺序,或者来自存储在 listview 中的数据的任何位置。所以尝试改变arraylist的顺序。

【讨论】:

    【解决方案2】:

    解决方案在于数据源。假设您从 sqlite 数据库中获取数据,当您查询数据库时,在列上使用 order by desc

    您需要指定数据源才能给出完整的答案。

    【讨论】:

      猜你喜欢
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多