【发布时间】:2017-10-10 11:29:56
【问题描述】:
我有一个显示送餐的列表视图,其项目由自定义 SimpleCursorAdapter 设置。
我为每个送餐或包含特别优惠等的列表视图项目显示一个额外的图标。我还在对列表进行排序,以便将带有特别优惠的送餐放在首位。
当列表视图第一次初始化时,一切都很好。当您滚动时,不包括特价商品的项目也有图标,并且列表视图混乱。
我猜这个问题来自视图回收,但我不知道如何解决它。
这是我的 SimpleCursorAdapter 类
private class MyCursorAdapter extends SimpleCursorAdapter{
private int rowLayout;
private Cursor cursor;
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
this.rowLayout=layout;
this.cursor=c;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
return inflater.inflate(this.rowLayout,null);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// get resources from database
int id = cursor.getInt(0);
int title = cursor.getInt(1);
final int specialOffer = cursor.getInt(7);
if (specialOffer==1){
// we have a special offer delivery
view.findViewById(R.id.offer_imageview).setVisibility(View.VISIBLE);
}
}
}
【问题讨论】:
-
如果条件不成立,您需要在
if (specialOffer==1)上添加一个else来隐藏ImageView。 -
好吧,那太尴尬了……非常感谢!
标签: android listview simplecursoradapter