how to modify data of a contact list using j2me?


salamu alikom

 i need to modify the data of contact list using PIM API so,plz,if any one have code to do this ,send it.

Assalamu alikom Eman,

hope that'll help:

first u need to return contact object:

Enumeration contacts = clist.items();  // clist is a ContactList obj

while(contacts.hasMoreElements())  {
Contact c = (Contact) contacts.nextElement();

//then any condition to select the contact

if( (c.getAttributes(Contact.NAME) != 0) & (c.getString(Contact.NAME,0).equals("name_existing") )

return c;


return null;

then here's a code to modify a contact

if(c != null)  {

String[] nameArray = new String[Contact.NAMESIZE];
       if (c.countValues(Contact.NAME) > 0) {
         c.removeValue(Contact.NAME, 0);
       nameArray[Contact.NAME_GIVEN] = "Kate";
       nameArray[Contact.NAME_FAMILY] = "Demeter";
       contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, nameArray); 

/* addStringArray(int field, int attributes, String[] value)
          Adds a string array value to the field  */

//saving data

 if(c.isModified()) {
        c.commit(); }

Note: you can not add data to a field that already contains data, the countValues method is invoked to determine whether or not the field is empty, and the removeValue method is used to remove the data from the field.