×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    5

    Post PIM Contact List inside LWUIT Tab

    I am new in j2me symbian mobile app development and I am trying to create an sms/chat app with two tabs. Tab1 contains a where the user will choose in a list of contacts and other one contains the new screen for chat. I manage to create a tab using LWUIT and I also have code in accessing the list of contacts as a new midlet. The problem is I don't know how to put it inside the tab as a component. Any suggestion/reference code how to do it? Thanks in advance!

    I managed to create some code:

    Code:
    import java.util.Enumeration;
    
    import javax.microedition.lcdui.Choice;
    import javax.microedition.lcdui.List;
    import javax.microedition.pim.Contact;
    import javax.microedition.pim.ContactList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;
    
    import com.sun.lwuit.Container;
    import com.sun.lwuit.Tabs;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.layouts.BoxLayout;
    
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.pim.*;
    
    import java.util.*;
    
    public class TabsDemo extends Demo {
    
        Tabs tp = null;
        List listContacts = null;
        ContactList contactList = null;
        
         public void cleanup() {
             tp = null;
         }
    
        public String getName() {
            return "";	
        }
    
        protected void executeDemo(Container f) {
            f.setLayout(new BorderLayout());
            f.setScrollable(false);
            tp = new Tabs();
    
            Container ContactListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
            ContactListPanel.setScrollableY(true);        
            tp.addTab("Contacts", ContactListPanel);
            
            
    
            Container radioButtonsPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
            radioButtonsPanel.setScrollableY(true);
    
    
       
            tp.addTab("Messages", radioButtonsPanel);
            
            f.addComponent("Center", tp);
            setupContactList();
          	//ContactListPanel.addComponent();
        }
        
        private void setupContactList() {
            listContacts = new List("Contact list", Choice.IMPLICIT);
            fillContactList();
        }
        
        private void fillContactList() {
            try {
        //        printString("Opening contact list ...");
                contactList = (ContactList)PIM.getInstance().openPIMList(
                        PIM.CONTACT_LIST, PIM.READ_WRITE);
    
            } catch (PIMException ex) {
      //          printString(ex.toString());
                return;
            }
            Enumeration contacts = null;
            Contact contact = null;
    /*        try {
                printString("Getting contact list items");
                contacts = contactList.items();
            } catch (PIMException ex) {
                releaseContactList();
                printString(ex.toString());
                return;
            }*/
            // Checking contact count
            if (!contacts.hasMoreElements()) {
                //printString("Contact list IS empty!");
            }
            if (listContacts.size() > 0) {
                listContacts.deleteAll();
            }
            while (contacts.hasMoreElements()) {
                contact = (Contact)contacts.nextElement();
                String contactInfo = contact.getStringArray(Contact.NAME,
                        Contact.ATTR_NONE)[Contact.NAME_GIVEN];
                if (contactInfo != null) {
                    listContacts.append(contactInfo, null);
                }
            }
        }
    
    
    }

  2. #2
    Registered User
    Join Date
    Dec 2012
    Location
    India
    Posts
    264

    Re: PIM Contact List inside LWUIT Tab

    You need to add listContacts to radioButtonsPanel container.Right now the container radioButtonsPanel is local to the function executeDemo().Make it global or restructure your code in such a way that you can add the list to the container.

  3. #3
    Registered User
    Join Date
    Apr 2014
    Posts
    5

    Re: PIM Contact List inside LWUIT Tab

    Hi. Is that the only reason/error why the contact list is not showing in the contact tab? Can you point me to the right direction how to get this done. I'm really have limited knowledge in j2me. Thanks.

  4. #4
    Registered User
    Join Date
    Dec 2012
    Location
    India
    Posts
    264

    Re: PIM Contact List inside LWUIT Tab

    Are you getting any other error ?

    If not,then yes.You have not added the list to radioButtonsPanel
    First make radioButtonsPanel global.
    Then at the end of fillContactList method,add the list to the radioButtonsPanel container

    radioButtonsPanel.addComponent(listContacts);

  5. #5
    Registered User
    Join Date
    Apr 2014
    Posts
    5

    Re: PIM Contact List inside LWUIT Tab

    I've reconstruct my code. It didn't show any error but it only display white screen on emulator.

    Here is my code:

    import java.util.Enumeration;

    import javax.microedition.lcdui.Choice;
    //import javax.microedition.lcdui.Displayable;
    //import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.Display;
    //import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.List;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.pim.Contact;
    import javax.microedition.pim.ContactList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;


    import com.sun.lwuit.Container;
    import com.sun.lwuit.Tabs;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.layouts.BoxLayout;

    public class TabMidlet extends MIDlet {

    Tabs tp = null;
    List listContacts = new List("Contact list", Choice.IMPLICIT);
    ContactList contactList = null;
    Display display;
    Container ContactListPanel = null;

    public void cleanup() {
    tp = null;
    }

    public String getName() {
    return "";
    }

    protected void executeDemo(Container f) {
    f.setLayout(new BorderLayout());
    f.setScrollable(false);
    tp = new Tabs();
    //Form fr = new Form();

    Container ContactListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    setupContactList();
    //openContactList();
    ContactListPanel.setScrollableY(true);
    tp.addTab("Contacts", ContactListPanel);

    Container MessageListPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    MessageListPanel.setScrollableY(true);
    tp.addTab("Messages", MessageListPanel);

    f.addComponent("Center", tp);


    }



    private void setupContactList() {


    openContactList();
    // releaseContactList();
    }

    /**
    * Fills listContacts fith data read from PIM database and brings
    * the list to the foreground.
    */
    private void openContactList() {

    try{
    fillContactList();
    display = Display.getDisplay(this);
    display.setCurrent(listContacts);
    printString("Done");
    }
    catch (Exception e) {
    e.printStackTrace();
    }

    }


    private void fillContactList() {
    try {
    printString("Opening contact list ...");
    contactList = (ContactList)PIM.getInstance().openPIMList(
    PIM.CONTACT_LIST, PIM.READ_WRITE);

    } catch (PIMException ex) {
    printString(ex.toString());
    return;
    }
    Enumeration contacts = null;
    Contact contact = null;
    try {
    printString("Getting contact list items");
    contacts = contactList.items();
    } catch (PIMException ex) {
    releaseContactList();
    printString(ex.toString());
    return;
    }
    // Checking contact count
    if (!contacts.hasMoreElements()) {
    printString("Contact list IS empty!");
    }
    if (listContacts.size() > 0) {
    listContacts.deleteAll();
    }
    while (contacts.hasMoreElements()) {
    contact = (Contact)contacts.nextElement();
    String contactInfo = contact.getStringArray(Contact.NAME,
    Contact.ATTR_NONE)[Contact.NAME_GIVEN];
    if (contactInfo != null) {
    listContacts.append(contactInfo, null);
    }
    }

    }

    /**
    * Closes the contact list if one is opened.
    */
    private void releaseContactList() {
    if (contactList != null) {
    try {
    printString("Closing contact list");
    contactList.close();
    } catch (PIMException ex) {
    printString(ex.toString());
    }
    }
    contactList = null;
    }

    /**
    * Prints a string on the screen.
    */
    private void printString(String text) {
    }

    protected void destroyApp(boolean unconditional)
    throws MIDletStateChangeException {

    }

    protected void pauseApp() {

    }

    protected void startApp() throws MIDletStateChangeException {

    }


    }
    Last edited by jejoybalm; 2014-04-06 at 04:24.

  6. #6
    Registered User
    Join Date
    Dec 2012
    Location
    India
    Posts
    264

    Re: PIM Contact List inside LWUIT Tab

    Hi

    You need to understand that the startApp method is called as soon as the app is launched.No other method gets called automatically.There is no code to execute in your startApp.

  7. #7
    Registered User
    Join Date
    Apr 2014
    Posts
    5

    Re: PIM Contact List inside LWUIT Tab

    Hello. you're right. i already think that's my problem. i've already try some code on startApp method but it emits some error like it is not applicable for the arguments. i cant figure out what to put. can you suggest me some solution? Thanks. your help is very much appreciated.
    Last edited by jejoybalm; 2014-04-08 at 09:55.

  8. #8
    Registered User
    Join Date
    Dec 2012
    Location
    India
    Posts
    264

    Re: PIM Contact List inside LWUIT Tab

    Please post the exact error message you are getting

  9. #9
    Registered User
    Join Date
    Apr 2014
    Posts
    5

    Re: PIM Contact List inside LWUIT Tab

    "The method getDisplay(MIDlet) in the type Display is not applicable for the arguments (TabsDemo)" i need to add the display method to show the contact list.

  10. #10
    Registered User
    Join Date
    Dec 2012
    Location
    India
    Posts
    264

    Re: PIM Contact List inside LWUIT Tab

    You need to pass a reference of the current MIDlet to the getDisplay method.(In most cases, using "this" should work)

    You are sending an instance of a class called TabsDemo, which I guess doenst extend MIDlet class.

Similar Threads

  1. LWUIT list scrolling is slow whenever list cells contain long strings
    By lordbritishix1982 in forum Mobile Java UI and User Experience
    Replies: 1
    Last Post: 2013-12-03, 18:08
  2. Add list after showing form (hack for lwuit s40 list bug)
    By xuanphung001 in forum Mobile Java General
    Replies: 2
    Last Post: 2013-04-24, 03:15
  3. How to append LWUIT List screen to a LWUIT Form in j2me?
    By pavanragi in forum Mobile Java General
    Replies: 1
    Last Post: 2012-08-06, 07:01
  4. How to create a combobox inside Lwuit Table
    By neerajj50@gmail.com in forum Mobile Java General
    Replies: 2
    Last Post: 2011-05-18, 06:05
  5. cannot add new contact list in my contact list application
    By dexth in forum Mobile Java General
    Replies: 0
    Last Post: 2009-10-10, 12:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •