【问题标题】:how to get selected items for listfiled checkbox in blackberry如何在黑莓中获取列表文件复选框的选定项目
【发布时间】:2012-03-07 06:52:25
【问题描述】:

我想在单击某个按钮时从列表字段复选框中获取选定的项目值。iam 使用int index1 = listField.getSelectedIndex(); 获取选定的索引,但我想要选定的项目值我的意思是字符串。如何得到它请给你的建议.我通过引用此链接link is:

尝试了我的代码

【问题讨论】:

    标签: blackberry listfield


    【解决方案1】:

    我认为这段代码会给你选择的数据

    ChecklistData data = (ChecklistData)_listData.elementAt(index);
    

    【讨论】:

    • 但我只得到最后选择的项目。我想假设我检查了两个项目,然后单击 getdata 意味着我需要显示这两个元素
    • 使用for循环查找选中的数据
    【解决方案2】:

    创建以下 MenuItem 并在添加 _toggleItem 时添加它

    final MenuItem _getDataMenu =new MenuItem("Get Data", 200, 10) {
        public void run(){
            int index = _checkList.getSelectedIndex();
            ChecklistData data = (ChecklistData)_listData.elementAt(index);
            String message = "Selected data: " + data.getStringVal() + ", and status: " + data.isChecked();
            Dialog.alert(message);
    
            // get all the checked data indices
            IntVector selectedIndex = new IntVector(0, 1);
            CheckListData data;
            for (int i=0;i<_listData.size();i++) {
                data = (CheckListData)_listData.elementAt(i);
                if(data.isChecked()) {
                    selectedIndex.addElement(i);
                }
            }
            data = null;
            // now selectedIndex will contain all the checked data indices.
        }
    };
    

    【讨论】:

    • 但我只得到最后选择的项目。我想假设我检查了两个项目,然后单击 getdata 意味着我需要显示这两个元素
    • 只需遍历 _listData 的所有元素,检查它们的状态,并将它们存储在某个地方。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    相关资源
    最近更新 更多