0

I am developing an application in Java me to send sms. It uses PIM library to fetch phone contacts and display it using CheckBox list. Users can select multiple contacts. I am using Vector to store selected element obtained using list.getSelectedItem()onActionEvent. The problem with this approach is that when user deselect an item it cannot be removed. Is there any simple way to remove deselected item from the Vector.

Sabin Jose
  • 658
  • 9
  • 19

3 Answers3

1

I think because you implement with ListcellRenderer you use the function setRenderer on list. This function work on the list that you work. You remove from vector but you don't update the list (ListcellRenderer used in the orginal list). Therefore you need update the list again(and call to setRenderer(..) ), whenever you remove from vector.

neb1
  • 209
  • 1
  • 12
1

I guess you cant remove a deselected number from the vector cause you cant identify it's index once it has been added to the vector. You can change the data structure and use a Hashtable instead, this way you can use a key, e.g. the number to identify the entry and when it is deselected, just look for the key and remove it.

Ajibola
  • 1,218
  • 16
  • 28
  • But how to idetify deseletion? the list does not produce any ActionEvent on deselection. – Sabin Jose Jan 14 '13 at 02:19
  • it should produce a click event, so the first click should be select, while second click for a particular number should be deselect. Alternatively, you could look into generic list cell renderer for lwuit. I used this for an SMS app that pulls from PIM Contacts list. – Ajibola Jan 14 '13 at 02:26
1

for having the ability to check and uncheck a list items you can use following procedure:

  • add a boolean variable to your list PIM objects

  • add a checkbox to the renderer which get its value from the boolean variable

  • then when a user click on each item, capture it using the list`s listener.

  • finally change the status of the boolean value to true or false in the listener.

    after that you have a list which its boolean variable shows which elements are selected by user.

Community
  • 1
  • 1
Navid
  • 901
  • 9
  • 20