×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    270

    How to display two labels in one cell of list view

    Issue 1 :
    I made lwuit listview and want to show three labels in each cell of list. For that i took one container and put labels in that. I am not getting labels one after other in list cell .
    Here is my code
    Code:
    public void startApp() {
    		//init the LWUIT Display
    		Display.init(this);
    	        mainForm = new Form("LWUIT List");
    		mainForm.setLayout( new BorderLayout());
    		Container con = new Container();
    		Label item1 = new Label("Item 1");
    		Label item2 = new Label("Item 2");
    		Label item3 = new Label("Item 3");
    		BoxLayout boxlayout = new BoxLayout(BoxLayout.Y_AXIS);
    		con.setLayout(boxlayout);
    		con.addComponent(item1);
    		con.addComponent(item2);
    		con.addComponent(item3);
    		List l=new List();
    		l.addItem(con);
    		mainForm.addComponent(BorderLayout.CENTER, l);
    		l.setRenderer(new MyRendered());
    		mainForm.show();
       }
    Here is my rendering class where i am getting error in setText . what should be used other than settext?
    Code:
    class MyRendered extends Container implements ListCellRenderer {
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
    setText(value.toString());     // GETTING ERROR HERE WHILE EXTENDING FROM CONTAINER
    if (isSelected) {
    
    
    setFocus(true);
    getStyle().setBgTransparency(100);
    getStyle().setBgColor(65281,true);
    getStyle().setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_ITALIC, Font.SIZE_MEDIUM));
    getStyle ().setBorder(Border.createRoundBorder (10, 10));
    
    
    } else {
    setFocus(false);
    getStyle().setBgTransparency(100);
    getStyle().setBgColor(7829368,true);
    //getStyle ().setBorder(Border.createRoundBorder (50, 50));
    getStyle ().setBorder(Border.createRoundBorder (10, 10));
    }
    return this;
    }
    
    public Component getListFocusComponent(List arg0) {
    return null;
    }

    Issue 2 : when getting list cells on implementing lwuit listview, i want to increase height of each list cell since by by default they have less height. How to do this?

    Thanks in advance
    Last edited by Manpreet_Singh; 2013-08-22 at 12:15.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: How to display two labels in one cell of list view

    i dont understand your way of adding components in the listview.

    You should create your labels inside your Renderer only and assign data in getListCellRendererComponent method !!

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    270

    Re: How to display two labels in one cell of list view

    I mentioned in the renderer as you said . I am getting null pointer exception . What steps i am missing. Here is what i applied

    Code:
    class MyRendered extends Container implements ListCellRenderer {
    	  private Label name = new Label();
    	  private Label email = new Label();
    
    
    	  private Label focus = new Label("");
    	 MyRendered() {
    		// TODO Auto-generated constructor stub
    	
    	      setLayout(new BorderLayout());
    	   
    	      Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    	      //cnt.getStyle().setBgColor(65281,true);
    	      setLayout(new BorderLayout());
    	      name.getStyle().setBgTransparency(0);
    	      name.getStyle().setBgColor(65281,true);
    	      name.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
    	      email.getStyle().setBgTransparency(0);
    	      cnt.addComponent(name);
    	      cnt.addComponent(email);
    	      addComponent(BorderLayout.CENTER, cnt);
    
    	      focus.getStyle().setBgTransparency(100);
    	  }
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
    //setText(value.toString());
    	  //Contact person = (Contact) value;
    
          name.setText("manpreet");
          email.setText("manpreetsingh@gmail.com");
        
          return this;
    }
    
    
    public Component getListFocusComponent(List arg0) {
    return null;
    }
    and this is my midlet class
    Code:
    public void startApp() {
    		//init the LWUIT Display
    		Display.init(this);
    		List l=new List();
    		mainForm = new Form("LWUIT List");
    		
    		l.setRenderer(new MyRendered());
    		
    	
    		mainForm.show();
    Last edited by Manpreet_Singh; 2013-08-23 at 07:58.

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

    Re: How to display two labels in one cell of list view

    In which line are you getting the null pointer exception ?

    I suggest you to set the List Model properly as right now there are no entries in the list.

    eg : ( From your code,I am assuming that u wish to use a class called Contact and it has the details of each person.The Contact class has a constructor which takes in a name and mail id.)

    Code:
    Display.init(this);
    List l=new List();
    mainForm = new Form("LWUIT List");
    l.setRenderer(new MyRendered());
    
    
    Contact contact_array[] = {new Contact("Name_1","Mail_1"),new Contact("Name_2","Mail_2")};
    
    ListModel lm = new DefaultListModel(contact_array);
    
    l.setModel(lm);
    
    mainForm.show();
    Test with this list model and see if you are able to see the List.

  5. #5
    Registered User
    Join Date
    May 2013
    Posts
    270

    Re: How to display two labels in one cell of list view

    Hi i m getting error in line
    Code:
    Contact contact_array[] = {new Contact("Name_1","Mail_1"),new Contact("Name_2","Mail_2")};
    cannot instantiate type contact

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: How to display two labels in one cell of list view

    so does your contact class support this sort of initialization !!

    I mean do you have this sort of constructor in your contact class ??

  7. #7
    Registered User
    Join Date
    May 2013
    Posts
    270

    Re: How to display two labels in one cell of list view

    actually my motive is not to use contact class. I was simply trying that example. I just want to display two labels in one cell one below other in boxlayout.

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: How to display two labels in one cell of list view

    as i have said many times on another threads you just have to write your own cell list renderer which should be straight forward other wise check this article :

    https://projects.developer.nokia.com..._ListDemo/wiki !!

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

    Re: How to display two labels in one cell of list view

    Hi

    I Had mentioned in my previous post itself

    eg : ( From your code,I am assuming that u wish to use a class called Contact and it has the details of each person.The Contact class has a constructor which takes in a name and mail id.) I did this because I saw this line

    Code:
     //Contact person = (Contact) value;
    This made me assume that you were going to use the contact class for populating the Model for the list.

    The example needs a constructor for the contact class which takes in two strings as input.I have attached the code for that as well now.

    Code:
    Class contact
    {
    String name;
    String mailID;
    
    Contact(String name,String mailID)
    {
    this.name = name;
    this.mailID = mailID;
    }
    public String getName()
    {
    return name;
    }
    public String getMailID()
    {
    return mailID;
    }
    
    }
    Here is your Renderer modified to use the contact class

    Code:
    class MyRendered extends Container implements ListCellRenderer {
    	  private Label name = new Label();
    	  private Label email = new Label();
    
    
    	  private Label focus = new Label("");
    	 MyRendered() {
    		// TODO Auto-generated constructor stub
    	
    	      setLayout(new BorderLayout());
    	   
    	      Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    	      //cnt.getStyle().setBgColor(65281,true);
    	      setLayout(new BorderLayout());
    	      name.getStyle().setBgTransparency(0);
    	      name.getStyle().setBgColor(65281,true);
    	      name.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
    	      email.getStyle().setBgTransparency(0);
    	      cnt.addComponent(name);
    	      cnt.addComponent(email);
    	      addComponent(BorderLayout.CENTER, cnt);
    
    	      focus.getStyle().setBgTransparency(100);
    	  }
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
    //setText(value.toString());
    	
          //MODIFIED CODE  
    
          Contact person = (Contact) value;
    
          name.setText(person.getName());
          email.setText(person.getMailID());
        
          return this;
    }
    
    
    public Component getListFocusComponent(List arg0) {
    return null;
    }
    I hope this makes the whole example clear.

Similar Threads

  1. Replies: 1
    Last Post: 2012-04-10, 08:44
  2. switching view from cell on grid to list view
    By khaivk in forum Symbian C++
    Replies: 4
    Last Post: 2011-01-24, 10:34
  3. Satellite view (without labels) in Ovi maps
    By ameypg in forum [Archived] Qt Mobility Project
    Replies: 0
    Last Post: 2011-01-13, 11:50
  4. Need to display the files list in List Box View.
    By jameskittu in forum Symbian C++
    Replies: 8
    Last Post: 2010-05-20, 11:24
  5. Custom list control (as labels)
    By AbuElElla in forum Symbian C++
    Replies: 9
    Last Post: 2009-09-14, 08:42

Posting Permissions

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