×

Discussion Board

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

    How to change the colour of selected label on list view

    I am working on s40 apps. How to change the colour of selected item in listview. I am using following code. but colour is not changing whenever i click from list 1 to list 2.
    also my ListCellrenderer interface is not working i guess. cz if i comment code of interface and class right below. still same output as it was without commented... for Plz help
    What updations i have to make in this code?
    Here is the code
    Code:
    public class mycspl extends MIDlet implements ActionListener
    {
      private Image logo;
      private Label logoLabel;
      private List menu;
      private Command select,exit; 
      public interface ListCellRenderer {
    
    	//This method is called by the List for each item, when the List paints itself.
    	public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected);
    
    	//This method returns the List animated focus.
    	public Component getListFocusComponent(List list);
    
    	} 
      public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected){
    	  return new Label(value.toString());
    	 }
    
    	 public Component getListFocusComponent(List list){
    	  return null;
    	 } 
    	 
      public void startApp() {
        Display.init(this);
        Form form1 =new Form();
        form1.getStyle().setBgColor(0xe5a812);
        try{
           // logo=Image.createImage("/images.png");
        }
        catch(Exception e){
            System.out.println("::::::"+e);
        }
        logoLabel=new Label(logo);
        select=new Command("Select");
        exit=new Command("Exit");
    
        //form1.setLayout(new BorderLayout());        
        //form1.addComponent(BorderLayout.NORTH,logoLabel);
        BoxLayout boxlayout=new BoxLayout(BoxLayout.Y_AXIS);
        form1.setLayout(boxlayout);
        form1.addComponent(logoLabel);
        logoLabel.setAlignment(Component.CENTER);
        logoLabel.getStyle().setBgColor(65281);
        menu=new List();
        menu.addItem("LIST 1");
        menu.addItem("LIST 2");
        form1.addComponent(menu);
        form1.addCommand(select);
        form1.addCommand(exit);
        form1.addCommandListener(this);
        form1.show();
    
      }
    
      public void pauseApp() {
      }
    
      public void destroyApp(boolean unconditional) {
      }
      public void actionPerformed(ActionEvent event){
        //int index=menu.getSelectedIndex();
        if(event.getCommand()==select && menu.getSelectedIndex()==0){
            System.out.println("Check list1");
    
    
        }
        if(event.getCommand()==select && menu.getSelectedIndex()==1){
            System.out.println("Check list 2");
        }
        if(event.getCommand()==exit){
            notifyDestroyed();
        }
      }
    
    }
    class MyRenderer extends Label{
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected){
     setText(value.toString());
    if (isSelected) {
       setFocus(true);
       getStyle().setBgTransparency(100);
       getStyle().setBgColor(0xe5a812,true);
    } else {
     setFocus(false);
       getStyle().setBgTransparency(0);
       getStyle().setBgColor(7829368,true);
    }
    return this;
    }
     }
    Last edited by wizard_hu_; 2013-07-28 at 11:59. Reason: QUOTE->CODE

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

    Re: How to change the colour of selected label on list view

    Hello Manpreet_Singh

    yes i dont understand the way you have coded your ListCellRenderer , please have a good look at this blog post http://lwuit.blogspot.in/2008/07/lwu...-fishbein.html i think somebody in your other post have already mentioned that and then start coding it.

    To give you some points:

    1. Make a class extend it from a Component or Container , implement the ListCellRenderer interface in it.
    2. Make your layout like add images and labels you want.
    3. Over ride your getListCellRendererComponent and from your model update your UI.
    4. there is a released parameter present in getListCellRendererComponent use that know if user has selected or released a content, update your ui accordingly.

    Regards,

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

    Re: How to change the colour of selected label on list view

    that i have done. Now i want that it should be separated in vertical cells .I mean there should be line dividing the cells. There should not be any space between two cells(or u can say a simple border).

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

    Re: How to change the colour of selected label on list view

    i think for that you need to override the paint method of the component from which you are extending your ListCellRenderer, and draw your own line , strings and images.

    I dont think there is any other simpler way except that !!

Similar Threads

  1. how to change the selected item in a list to a string format
    By dilmeetkaur in forum General Messaging
    Replies: 1
    Last Post: 2009-11-05, 14:35
  2. how to change the selected item in a list to a string format
    By dilmeetkaur in forum General Messaging
    Replies: 1
    Last Post: 2009-11-05, 14:35
  3. can i change the backgrnd of List View?
    By nital_shah in forum Symbian
    Replies: 8
    Last Post: 2009-06-18, 14:06
  4. Replies: 2
    Last Post: 2006-06-21, 10:05
  5. Replies: 6
    Last Post: 2006-04-18, 10:27

Posting Permissions

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