android显示多个复选框,android - 在长列表视图中选择特定的复选框会选中多个复选框 - 堆栈内存溢出...

我有一个带复选框的列表视图。 我单击特定的项目,将选中相应的复选框,但它还会在列表视图中每隔8-10行后重复选择复选框。 我了解发生这种情况是因为在android系统中,仅针对可见屏幕的视图被存储用于内存优化。 但是我无法克服这种情况。 请建议。

public class FBFriendsListAdaptor extends ArrayAdapter{

private final Context context;

private static List items;

private SparseArray checkedItems = new SparseArray();

ViewHolder holder;

public FBFriendsListAdaptor(Context context, List items) {

super(context, R.layout.fb_friend_list, items);

this.items = items;

this.context = context;

}

@Override

public FBFriendItem getItem(int position) {

// TODO Auto-generated method stub

return items.get(position);

}

public View getView(final int position, View convertView, ViewGroup parent) {

View v = convertView;

if (v == null) {

LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

v = vi.inflate(R.layout.fb_friend_list, parent, false);

}

holder = new ViewHolder();

holder.selectFriendCB = (CheckBox)v.findViewById(R.id.selectFriendCB);

v.setTag(holder);

v.setOnClickListener(new View.OnClickListener(){

public void onClick(View v) {

if (checkedItems.get(position) != null){

checkedItems.remove(position);

holder.selectFriendCB.setChecked(false);

}

else {

checkedItems.put(position, items.get(position));

holder.selectFriendCB.setChecked(true);

}

}

});

FBFriendItem item = items.get(position);

TextView firstNameTV = (TextView) v.findViewById(R.id.firstNameTV);

TextView lastNameTV = (TextView) v.findViewById(R.id.lastNameTV);

ImageView picIV = (ImageView) v.findViewById(R.id.picIV);

if (!item.getFbId().isEmpty()) {

firstNameTV.setText(" " + item.getFirstName());

lastNameTV.setText(" " + item.getLastName());

Bitmap image = item.getImage();

if(image != null) {

picIV.setImageBitmap(image);

}

}

return v;

}

public SparseArray getCheckedItems(){

return checkedItems;

}

static class ViewHolder {

CheckBox selectFriendCB;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值