1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
public
class
CheckBoxAdapter4TextNote
extends
SimpleCursorAdapter
{
private
ArrayList
new
ArrayList
//记录被选中条目id
private
int
mCheckBoxId =
0
;
//listView条目的样式对应的xml资源文件名(必须包含checkbox)
private
String mIdColumn;
//数据库表的id名称
public
CheckBoxAdapter4TextNote(Context context,
int
layout, Cursor c,
String[] from,
int
[] to,
int
checkBoxId, String idColumn,
int
flags)
{
super
(context, layout, c, from, to, flags);
mCheckBoxId = checkBoxId;
mIdColumn = idColumn;
}
@Override
public
int
getCount()
{
return
super
.getCount();
}
@Override
public
Object getItem(
int
position)
{
return
super
.getItem(position);
}
@Override
public
long
getItemId(
int
position)
{
return
super
.getItemId(position);
}
@Override
public
View getView(
final
int
position, View convertView,
ViewGroup parent)
{
View view =
super
.getView(position, convertView, parent);
final
CheckBox checkbox = (CheckBox) view.findViewById(mCheckBoxId);
checkbox.setOnClickListener(
new
OnClickListener()
{
@Override
public
void
onClick(View v)
{
Cursor cursor = getCursor();
cursor.moveToPosition(position);
checkbox.setChecked(checkbox.isChecked());
if
(checkbox.isChecked())
//如果被选中则将id保存到集合中
{
selection.add(cursor.getInt(cursor.getColumnIndex(mIdColumn)));
}
else
//否则移除
{
selection.remove(
new
Integer(cursor.getInt(cursor.getColumnIndex(mIdColumn))));
Toast.makeText(context,
"has removed "
+ cursor.getInt(cursor.getColumnIndex(mIdColumn)),
0
).show();
}
}
});
return
view;
}
/返回集合
public
ArrayList
{
return
selection;
}
}
|
1
2
3
4
5
|
List
for
(
int
id : bn)
{
//TODO 执行删除操作
}
|