java SimpleCursorAdapter删除值
我在每一行都有一个ListView
,我有一个LinearLayout
,其中有一些对象(主要是一些文本视图)
我用光标动态填充这个列表视图。在这个游标中,我有一个值true或false
我想隐藏或使值为false的行不可单击。我尝试了这个代码,但不起作用
public void contentProviderInitialized(final Cursor cursor) {
SimpleCursorAdapter commonTickets = new SimpleCursorAdapter(MyClass.this,
R.layout.row_ticketing, cursor, new String[] {"price", "productName", "stopName" },
new int[] { R.id.ticketing_price, R.id.ticketing_product, R.id.ticketing_stop_name }
) {
@Override
public void bindView(View view, Context context, Cursor cursor) {
String enabledStr = cursor.getString(cursor.getColumnIndex("enabled"));
String product = cursor.getString(cursor.getColumnIndex("productName"));
boolean enabled = Boolean.parseBoolean(enabledStr);
LinearLayout ticketingRow = (LinearLayout) view.findViewById(R.id.ticketing_row);
if (enabled) {
ticketingRow.setEnabled(true);
} else {
ticketingRow.setEnabled(false);
}
super.bindView(view, context, cursor);
};
MyClass.this.ticketing_list_view.setAdapter(commonTickets);
}
}
# 1 楼答案
这对尝试另一种方法很有帮助:
Android - how to delete item from a cursor?
将要查看的位置添加到新矩阵光标,并将光标切换到新矩阵光标
# 2 楼答案
已在适配器上启用覆盖
http://developer.android.com/reference/android/widget/BaseAdapter.html#isEnabled(int)
这个答案似乎暗示了这一点。在光标上使用movetoposition。不过,这听起来性能会很差,所以您可能希望基于数字位置对真/假值进行缓存?试试看。看看进展如何。缓存可能是一种浪费