SelectionListener for Container

49 views
Skip to first unread message

Hùng Phạm

unread,
Oct 2, 2014, 7:46:33 AM10/2/14
to codenameone...@googlegroups.com
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Desktop OS : Window
Simulator
------------------------------------------------------------- 
Dear Mr. Shai.
I got a problem about using tablelayout. It can not be full in screen that i expect.
By the way, could you give me idea to catch selection event when user click on the container.
(The container looks like a items of list on the right figure)
somecode.java
             layout = new TableLayout(5, 2);
            TableLayout.Constraint ct = layout.createConstraint();
            ct.setHorizontalSpan(2);
            lbName = new SpanLabel(); 
            lbName.setUIID("LabelTitle");
            lbSender = new Label();
            lbSenderDate = new Label();
......
            this.addComponent( ct,lbName);
            this.addComponent(lbSender);

Thank you !


Shai Almog

unread,
Oct 2, 2014, 1:15:29 PM10/2/14
to codenameone...@googlegroups.com
Hi,
I'm assuming that what you want about selection event is really the lead component: http://www.codenameone.com/blog/leading

Define the column width constraint to -2 to make it take up the rest of available space.

Hùng Phạm

unread,
Oct 6, 2014, 5:55:30 AM10/6/14
to codenameone...@googlegroups.com

Thank for your suggestion.
I wonder if I dont have any button in my container( Ex: my container has only label).
 I can not catch the event like ActionListener via setLeadComponent() approach. 

Chen Fishbein

unread,
Oct 6, 2014, 3:30:22 PM10/6/14
to codenameone...@googlegroups.com
The button does not have to be on the Container

            Button lead = new Button();
            lead.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                }
            });
            container.setLeadComponent(lead);

Hùng Phạm

unread,
Oct 6, 2014, 10:25:35 PM10/6/14
to codenameone...@googlegroups.com
Thank Chen.
But i think it should be appropriate with one or two container. (We set 2 button to listen event on each container)
In my situation, I have list of container like that( You can see in first post)
It would suggest me to make a dummy button to catch this event but dont show it on UI. 
Is it a good idea?

Shai Almog

unread,
Oct 6, 2014, 11:50:12 PM10/6/14
to codenameone...@googlegroups.com
Did you try Chen's suggestion?
See http://www.codenameone.com/blog/leading

Hùng Phạm

unread,
Oct 7, 2014, 2:42:17 AM10/7/14
to codenameone...@googlegroups.com
Yes, i did it. 
I want to catch event like press/ long press on my custom list. My custom list contains list of container. Each of item container have only Label or SpanLabel. 
Following setLeadComponent() approach, we have to add a dummy button on each items to determine which item pressed and dont show this button on UI
// Somecode.java

Container center = new Container();
center.addComponent( ItemTaskItem[]);

 class ItemTaskView extends Container {
     
        private SpanLabel lbSender, lbSenderDate, lbReceiver, lbStartDate, lbCode, lbStatus;
        SpanLabel lbName;
      ..
Button dummy = new Button();
this.setLeadComponent(dummy);
dummy.setActionListener( ...)
}

Shai Almog

unread,
Oct 7, 2014, 9:45:22 AM10/7/14
to codenameone...@googlegroups.com
If this is in the renderer then you need to do something else entirely: http://www.codenameone.com/blog/deeper-in-the-renderer
Reply all
Reply to author
Forward
0 new messages