添加日期分隔符为Android的一个SimpleCursorAdapter日期、分隔符、SimpleCursorAdapter、Android

2023-09-05 08:22:06 作者:浅歌゛勿忘初心

我已经安装在我看来,一个SimpleCursorAdapter,它工作正常,当我从我的数据库获取数据。该查询使用ORDER BY日期DESC子句中运行。所有行被提取,并在我的ListView很好地显示出来,我使用adapter.setViewBinder(),以一些逻辑添加到项目(增加了缩略图)。

I have setup a SimpleCursorAdapter on my view and it works fine when I'm fetching the data from my database. The query is run using a ORDER BY date DESC-clause. All rows are fetched and displayed nicely in my ListView, and I'm using adapter.setViewBinder() to add some logic to the items (adding a thumbnail).

在code是这样的:

// Setup the adapter
adapter = new SimpleCursorAdapter(this, R.layout.rowitem, cursor, FROM, TO);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
  @Override
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    // Only taylor the ImageView in the adapter-list, skip everything else.
    if (view.getId() != R.id.imageItem)
      return false;

    // here goes the logic, but it's cut away due to its size

    }

    return true;
  }
});

现在我想添加一些更多的逻辑:我想补充包含日期的小分隔栏,如果日期是两个项目之间的变化,这样的:

Now I want to add some more logic: I want to add a small separator bar containing the date if the date is changed between two items, like this:

=== DATE1 ===============
Item 1
Item 2
=== DATE2 ===============
Item 3
=== DATE3 ===============
Item 4
Item 5
Item 6
=== DATE4 ===============
Item 7

等。但是,我不知道如何插入一个新视图元素的适配器的内部,我似乎无法找到developer.android.com答案。

and so on. However, I'm not sure how to insert a new View-element inside of an adapter and I cannot seem to find an answer on developer.android.com.

我怎样才能做到这一点?

How can I accomplish this?

推荐答案

- 编辑 -

好这里是这个问题的一个简单的解决方案:

Okay here is an easy solution for this problem:

Custom ListView控件与日期为SectionHeader(使用定制SimpleCursorAdapter)

---旧帖子--- 我不能对你的第一篇文章发表评论,但我想恳请你,如果你能在一个更详细一点,你如何设法得到该列表日期头解释。 你将不得不遍历所有的光标,行还是有框架提供一个更好的办法?

--- old post --- I couldn't comment on your first Post but I wanted to kindly ask you if you could explain in a little more detail how you managed to get this list with date headers. You would have to iterate over all the curser-rows or is there a better way provided by the framework?

我有好几个项目,如果我重复与而(listData.moveToNext()){它需要长。 (我也有从unixtime戳来计算一个日历,一个日期,到一个月 - 诠释)。

I have quite a few items and if I iterate with while(listData.moveToNext()){ it takes to long. (I also have to calculate from a unixtime stamp to a Calendar, to a Date, to a month-Int).