action event on a Table so that when I access a cell I can take an action like popup a dialog of choices

8 views
Skip to first unread message

shop.servic...@gmail.com

unread,
Aug 5, 2017, 1:56:38 PM8/5/17
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA NetBeans 8.2
Desktop OS Windows 10
Simulator 7.3
Device Simulator

I too am a Swing Developer and am looking for an action event on a Table so that
when I access a cell (focusgained) I can take an action like popup a dialog of choices, however
I am not sure which listener to use.
I have looked at the addFocusListener, however I do not receive focusGained or focusLost event

        A3TimeSheetTable is of class  com.codename1.ui.table.Table

        A3TimeSheetTable.addFocusListener(new com.codename1.ui.events.FocusListener() {
           
            @Override
            public void focusLost(Component cmp) {
                System.out.println("focus Lost Component = "+cmp);
            }
            @Override
            public void focusGained(Component cmp) {
                System.out.println("focus Gained Component = "+cmp);
            }
        });

Shai Almog

unread,
Aug 6, 2017, 3:00:55 AM8/6/17
to CodenameOne Discussions, shop.servic...@gmail.com
Focus is a bad approach for touch devices so we don't usually use it. If you look at the sample code in the Table JavaDoc https://www.codenameone.com/javadoc/com/codename1/ui/table/Table.html

You will see how we work with cells individually. Unlike the swing approach of renderer/editor we literally return the component instance and you can bind a listener to that. It's not as "hugely scalalble" as the Swing approach but if you plan to have 1000 cells on a mobile device this will be a usability nightmare.

shop.servic...@gmail.com

unread,
Aug 6, 2017, 9:23:11 PM8/6/17
to CodenameOne Discussions, shop.servic...@gmail.com
My app will contain perhaps 20 rows in this instance.
Using the method described in Table.html,  processing an Table event with createCell(Object value, int row, int column, boolean editable)
iterates all rows and super.getSelectedRow() does not return the row In the table I touched.

1) I really need to know which event I can use that will allow me to know which row/column was fired

2) Does this Table implementation support rendering a Picker Object or TextField?

Regards.


On Sunday, August 6, 2017 at 3:00:55 AM UTC-4, Shai Almog wrote:

Shai Almog

unread,
Aug 7, 2017, 1:57:39 AM8/7/17
to CodenameOne Discussions, shop.servic...@gmail.com
The demo code there includes a picker cell.
When you bind the listener you have the cell row/column information right there in the method.

shop.servic...@gmail.com

unread,
Aug 7, 2017, 9:42:54 AM8/7/17
to CodenameOne Discussions, shop.servic...@gmail.com
overriding createCell and adding action listener to the individual cells does the job.

cell.addPointerPressedListener(new ActionListener() {
                                public void actionPerformed(ActionEvent evt) {
                                    System.out.println("addPointerPressedListener selected Row = " + A3TimeSheetTable.getSelectedRow() + " selected Column = " + A3TimeSheetTable.getSelectedColumn());
                                }
                            });

Thanks.


On Monday, August 7, 2017 at 1:57:39 AM UTC-4, Shai Almog wrote:
Reply all
Reply to author
Forward
0 new messages