action event not getting fired for a button on form

85 views
Skip to first unread message

nir...@nvsoft.com

unread,
Dec 12, 2013, 3:03:00 PM12/12/13
to codenameone...@googlegroups.com
Hi Shai,

I am facing a strange issue. I have a button added in a form in my resource file through gui builder and have overridden the action performed event in StateMachine.java. However when I click that button the event callback is not getting called, but if I using the arrow keys on keyboard (on simulator) it is calling the event.

I am not able to figure out why the pointer click event is not calling the event callback method.

I tested the code on simulator and actual device (android) and it is not calling the event callback on this button.

I have attached my resource file for your reference. The problem component is "PlaceOrder" button in the "S2PayID" form. 

The callback method name is given below which is implemented in the StateMachine.java

    protected void onS2PayID_PlaceOrderAction(Component c, ActionEvent event) {
}

Can you please see what could be the issue?

Thanks,
Nirmal
s2payTheme.res

Shai Almog

unread,
Dec 13, 2013, 1:37:22 AM12/13/13
to codenameone...@googlegroups.com, nir...@nvsoft.com
Hi Nirmal,
the command is marked as a back command which might be falling into some edge case. Why is this marked as a back command?

Nirmal Juthani

unread,
Dec 13, 2013, 2:17:18 AM12/13/13
to Shai Almog, codenameone...@googlegroups.com
Hi Shai,

I am not sure, where you are seeing that button marked as back
command. Actually the button which is causing the problem is not
marked as back command. However in the beforeS2PayID() method(of the
form where this button was added) we have added the following code:

protected void beforeS2PayID(Form f) {
// TODO Auto-generated method stub
super.beforeS2PayID(f);
Command back = new Command("Back") {

public void actionPerformed(ActionEvent evt) {
if (orderFromMenuMode) {
orderFromMenuMode = false;
setBackDestination("MainUI");
}
back();
}
};
f.setBackCommand(back);
}

This is done so that when using the hardware back button on the
android devices, we want to clear the navigation stack and take user
to the main ui.

However somehow, the button in this form is not getting any action
events. Please note in the simulator if you bring the focus to that
button using keyboard, and then press Enter key, then it fires the
actionListener event.

Thanks,
Nirmal

Shai Almog

unread,
Dec 13, 2013, 2:17:09 PM12/13/13
to codenameone...@googlegroups.com, Shai Almog, nir...@nvsoft.com
On the form S2PayID I only see one button named home.
Clicking its command has the "back command" flag set.
Check that one of its parent containers isn't marked as focusable.

nir...@nvsoft.com

unread,
Dec 14, 2013, 9:30:53 PM12/14/13
to codenameone...@googlegroups.com, nir...@nvsoft.com
Hi Shai,

Thanks for quick response, You are right, the parent container where the button is added is marked as Focusable. After I unmark it, the event is getting fired for the button.

Does that mean, whenever you want to add a button inside a container, the parent container should be marked as unfocusable? If possible can you please guide what is the best practice.

Thanks,
Nirmal

Shai Almog

unread,
Dec 15, 2013, 1:01:38 AM12/15/13
to codenameone...@googlegroups.com, nir...@nvsoft.com
Hi,
no.
You must have inadvertently enabled focusable by mistake.
Codename One doesn't support nesting focusable components one within another.
Reply all
Reply to author
Forward
0 new messages