Search code examples
blackberrylistfield

how to get selected items for listfiled checkbox in blackberry


i want to get the selected item values from listfield checkbox when clicking on some button .iam getting the selected index by using int index1 = listField.getSelectedIndex(); but i want that selected item values i mean that string.how to get that please give your suggestions.i tried my code by refering this link link is:


Solution

  • Create following MenuItem and add that as you added the _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.
        }
    };