开发者

Android: Using data from a multiple-column ArrayList in a ListView

开发者 https://www.devze.com 2023-01-31 14:01 出处:网络
Currently I am displaying data from an SQLite database in a multiple-column ListView. However, I would like to use calculated columns in my data involving more complicated mathematical functions than

Currently I am displaying data from an SQLite database in a multiple-column ListView. However, I would like to use calculated columns in my data involving more complicated mathematical functions than those available in SQLite queries. In this thread the following advice was given for this sort of situation:

... if you are putting the Cursor into some sort of CursorAdapter, you could: (1) convert the Cursor into an ArrayList, where Position is some Java class you define with your data (2) close the Cursor, to release the RAM it takes up (3) sort the ArrayList using Arrays.sort() (4) wrap the ArrayList in an ArrayAdapter and use that where you had been using your CursorAdapter

My problem is that I get stuck at step (4), because ArrayAdapter seems to be less fl开发者_运维问答exible than SimpleCursorAdapter. I have been using SimpleCursorAdapter to define the mapping from the database columns to the ListView, but there seems to be no equivalent method defined for an ArrayAdapter.

I have seen references on the web to an Android object called ArrayListCursor. This sounds as if it would do just what I want, but it does not appear in the current Android Reference and it doesn't seem to be recognised by Eclipse.

If ArrayListCursor has been superseded what has replaced it?


I do not remember ever seeing an ArrayListCursor. There is a MatrixCursor, which allows you to build up a Cursor from rows and cells. You can also implement AbstractCursor to do whatever you want.

Whatever you do, try to minimize the data copying you do, which is why I would recommend either:

  • Creating your own AbstractCursor subclass that wraps your database Cursor and blends in the calculated values
  • Just leave your original Cursor alone and use a CursorAdapter subclass to blend in your calculated values
0

精彩评论

暂无评论...
验证码 换一张
取 消