从游标过滤行,使他们不ListView中显示游标、使他、ListView

2023-09-12 23:50:02 作者:清欢百味

我有一个光标,返回我用SimpleCursorAdapter用它来填充一个ListView行。我想过滤某些行,所以它们不会显示在我的ListView。我使用的数据来自其他地方我活动的行,所以我不想改变我的SQL将它们与一个过滤器WHERE子句。

I have a Cursor that returns rows I use with a SimpleCursorAdapter to populate a ListView. I would like to filter some of the rows so they don't get displayed in my ListView. I use the data from the rows elsewhere in my Activity so I don't want to change my SQL to filter them with a WHERE clause.

什么是保持一个行被显示在我的ListView最好的方法是什么?理想情况下我会检查一列在我的行,然后只行添加到满足条件的ListView控件。

What is the best way to keep a row from being displaying in my ListView? Ideally I would check a column in my row and then only add rows to the ListView that satisfy a condition.

推荐答案

创建一个 CursorWrapper 并覆盖动...()方法职位改在过滤的(这是什么的ListView 将看到)和岗位实际光标。然后,用你的 CursorWrapper SimpleCursorAdapter

Create a CursorWrapper and override the move...() methods to convert positions in the filtered set (which is what the ListView will see) and positions in the actual Cursor. Then, use your CursorWrapper in the SimpleCursorAdapter.