使用droidQuery库,这真的很容易。在你的活动中,调用这个:
$.with(this).selectByType(Checkbox.class.getName()).each(new Function() {
@Override
public void invoke($ droidQuery, Object... params) {
Checkbox cb = (Checkbox) droidQuery.view(0);
//TODO: manipulate each checkbox here.
}
});
要添加点击侦听器,只需添加链调用click
(替代,或在末尾):
本身
$.with(this).selectByType(Checkbox.class.getName()).click(new Function() {
@Override
public void invoke($ droidQuery, Object... params) {
Checkbox cb = (Checkbox) droidQuery.view(0);
//TODO: handle the clicked Checkbox
}
});
链式调用
$.with(this).selectByType(Checkbox.class.getName()).each(new Function() {
@Override
public void invoke($ droidQuery, Object... params) {
Checkbox cb = (Checkbox) droidQuery.view(0);
//TODO: manipulate each checkbox here.
}
}).click(new Function() {
@Override
public void invoke($ droidQuery, Object... params) {
Checkbox cb = (Checkbox) droidQuery.view(0);
//TODO: handle the clicked Checkbox
}
});