listview中使用getCheckItemIds和getCheckedItemIds获取选中项

来源:互联网 发布:洞洞板画图软件 编辑:程序博客网 时间:2024/05/24 05:16

1、使用 listview .getCheckItemIds();(已弃用)

使用此方法获取选中项需要重写adapter中的以下方法才会有效:

@Overridepublic long getItemId(int position) {    // TODO Auto-generated method stub    // position 值可自定义    return position;}

这个需要 return position;

2、使用 listview.getCheckedItemIds();

使用此方法需要重写adapter中的以下方法才会有效:

@Overridepublic boolean hasStableIds() {    // TODO Auto-generated method stub    return true ;}

这个需要return true才会有作用;

第一种已弃用,建议使用第二种;

1 0
原创粉丝点击