黑莓 - 获取从复选框列表中选中的项 [英] Blackberry - get checked items from list with checkboxes
问题描述
如何检查所有从列表中的项目可以获取的?
How can all checked items from a list can be fetched?
我需要得到列表中的所有选择(选中)项目和填充的矢量。
I need to get all selected (checked) items from the list and populate a vector.
我没有得到所有选定的项目,我只得到上目前的重点是该项目。
I am not getting all selected items, I am getting only the item on which current focus is.
我实现listfield与复选框根据的知识库文章。
I am implementing listfield with checkboxes as per the knowledgebase article.
如果我使用getSelection(),它返回我当前突出显示列表行的索引,而不是已经检查了所有。
If I use getSelection(), it is returning me the currently highlighted list row index, and not all that have been checked.
推荐答案
正如我undestood,样品是<一个href=\"http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/How_To_-_Create_a_ListField_with_check_boxes.html?nodeid=1165752&vernum=0\"相对=nofollow>如何 - 创建一个ListField与复选框
As I undestood, sample is How To - Create a ListField with check boxes
然后就可以添加矢量到ListFieldCallback实现类:
Then you can add Vector to the class where ListFieldCallback is implemented:
private Vector _checkedData = new Vector();
public Vector getCheckedItems() {
return _checkedData;
}
和更新drawListRow是这样的:
and update drawListRow this way:
if (currentRow.isChecked())
{
if( -1 ==_checkedData.indexOf(currentRow))
_checkedData.addElement(currentRow);
rowString.append(Characters.BALLOT_BOX_WITH_CHECK);
}
else
{
if( -1 !=_checkedData.indexOf(currentRow))
_checkedData.removeElement(currentRow);
rowString.append(Characters.BALLOT_BOX);
}
如果您将使用VerticalFieldManager自定义CheckBoxField字段,你可以遍历屏幕上的所有字段(或经理),并检查其复选框字段,然后取一个值:
If you would use VerticalFieldManager with custom CheckBoxField, you could iterate over all fields on screen (or any manager) and check if its' checkbox field, then take a value:
class List extends VerticalFieldManager {
...
public Vector getCheckedItems() {
Vector result = new Vector();
for (int i = 0, cnt = getFieldCount(); i < cnt; i++) {
Field field = getField(i);
if (field instanceof CheckboxField) {
CheckboxField checkboxField = (CheckboxField) field;
if (checkboxField.isChecked())
result.addElement(checkboxField);
}
}
return result;
}
}
这篇关于黑莓 - 获取从复选框列表中选中的项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!