Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
VBRefugee
Posts: 47
Registered: ‎02-26-2010
My Device: Torch 9850
Accepted Solution

CONSUME_CLICK style doesn't work

Working on an device app that's going to access specific internet sites using hard coded URLs derived from the user clicking buttons.

 

Thus far, I haven't gotten to handling the actual button clicks because the CONSUME_CLICK style is being ignored and I get the Dialog.inform box displayed when I close the application if I've clicked one of the buttons.

 

If one of you could advise what I've left out or stated wrongly, I would greatly appreciate it.

 

Here is the code:

 

(App's First Screen:smileyhappy:

 

package com.avwx.ui;

import net.rim.device.api.ui.UiApplication;

public class AvWxApp extends UiApplication {

    public AvWxApp() {
        
        AvWxMainScreen mainScreen = new AvWxMainScreen();
        pushScreen(mainScreen);}
    
        public static void main(String[] args) {
        AvWxApp app = new AvWxApp();
        app.enterEventDispatcher();
        
    }

}


(App's Second Screen:smileyhappy:

package com.avwx.ui;

//import net.rim.device.api.ui.Field;
//import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.HorizontalFieldManager;

public class AvWxMainScreen extends MainScreen {
        public AvWxMainScreen() {
                
ButtonField SSECButton;
ButtonField SFCWXButton;
ButtonField PROG12Button;
ButtonField PROG24Button;
ButtonField PROG36Button;
ButtonField PROG48Button;

SSECButton = new ButtonField("SSEC", ButtonField.CONSUME_CLICK );
SFCWXButton = new ButtonField("SFC WX", ButtonField.CONSUME_CLICK );
PROG12Button = new ButtonField("PRG12", ButtonField.CONSUME_CLICK );
PROG24Button = new ButtonField("PRG24", ButtonField.CONSUME_CLICK );
PROG36Button = new ButtonField("PRG36", ButtonField.CONSUME_CLICK );
PROG48Button = new ButtonField("PRG48", ButtonField.CONSUME_CLICK );

HorizontalFieldManager buttonManager = new HorizontalFieldManager(FIELD_LEFT);
buttonManager.add(SSECButton);
buttonManager.add(SFCWXButton);
buttonManager.add(PROG12Button);
add(buttonManager);

HorizontalFieldManager buttonManager1 = new HorizontalFieldManager(FIELD_LEFT);
buttonManager1.add(PROG24Button);
buttonManager1.add(PROG36Button);
buttonManager1.add(PROG48Button);
add(buttonManager1);

    }
}

   

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: CONSUME_CLICK style doesn't work

Can you describe the issue more clearly?

 

You need to add a listener to the buttons or override navigationClick() - I don't see how you can tell if the "CONSUME_CLICK" is working or not, based on your code.

 

 

 

 

 

Contributor
VBRefugee
Posts: 47
Registered: ‎02-26-2010
My Device: Torch 9850

Re: CONSUME_CLICK style doesn't work

Thanks for the reply.

 

I haven't gotten to the listener function yet. I am just checking the basic navigation functionality of the button display.

 

When I run the application against the simulator, the buttons can be accessed, meaning you can move between the buttons and focus is changing as you move between the array (assuming the changing color of the button as you move between the means focus is changing.

 

At this point if I click on a button, nothing happens since I haven't implimented the listener function yet.

 

Anyway, when I close down the application, the Dialog box comes up saying with the Change, Discard, Cancel display.

 

Are you saying that unless I implement the listener function, this is normal behavior?

 

 

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: CONSUME_CLICK style doesn't work

No, you said "dialog inform", which was meaningless to me.

 

You can easily correct this behavior by overriding the onSave() and/or onSavePrompt methods in your screen.

 

See the javadocs.

 

 

 

 

Contributor
VBRefugee
Posts: 47
Registered: ‎02-26-2010
My Device: Torch 9850

Re: CONSUME_CLICK style doesn't work

RexDoug:

 

Thank you for your reply.

 

I'm unfamiliar with how to implement your suggestion (admittedly not up to speed on Java ME app development yet.)  Could you please provide a code snippet to call the onSave method as an overide?

 

Also, my understanding is ButtonField.CONSUME_CLICK is supposed to prevent exactly this sort of behavior without the need to do the override you speak of.

 

If it doesn't mask the click event  to prevent the dialog box, what good is it?

 

Thanks for your patience and help.

Developer
hades_6
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: CONSUME_CLICK style doesn't work

http://supportforums.blackberry.com/t5/Java-Development/Save-Discard-Cancel-and-all-that/m-p/436366

 

 

Refer to the last post, first method. Search the forum, before you start up a new thread.

Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: CONSUME_CLICK style doesn't work

If it doesn't mask the click event  to prevent the dialog box, what good is it?

The CONSUME_CLICK style consumes the click event on the *button you apply it to*, not when you hit Menu-Close or some other method to close your application. The onSave popup is related, see the above link you were pointed to, etc.

Contributor
VBRefugee
Posts: 47
Registered: ‎02-26-2010
My Device: Torch 9850

Re: CONSUME_CLICK style doesn't work

[ Edited ]

Thanks for your input.  I'm a new BB/Java ME programmer and that is part of the problem I'm sure.

 

 

Developer
jMarc
Posts: 94
Registered: ‎10-01-2009
My Device: Not Specified

Re: CONSUME_CLICK style doesn't work

CONSUME_CLICK style works just fine, but it has nothing to do with the popup you're seeing.

 

You get the popup when you close a screen that has one or more components that have been changed, that is, marked "dirty". It's asking what you want to do with the changes. Typing in a text field or clicking a button are examples of things that mark a component "dirty".

 

CONSUME_CLICK tells the button it should not pass the click event on to its parent field after its listener has run. The click makes the button "dirty" regardless of whether the button consumes the click.

 

You can add NEVER_DIRTY to your button style, instead of or in addition to CONSUME_CLICK. Then the click won't set the "dirty" flag and you won't get the popup. You can decide later if you need to deal with dirty buttons some other way, like in the listener or by overriding onSave or onSavePrompt, as RexDoug mentions.

Contributor
VBRefugee
Posts: 47
Registered: ‎02-26-2010
My Device: Torch 9850

Re: CONSUME_CLICK style doesn't work

jmarc:  Thank you for that very clear explaination.

 

After your explaination, I stopped messing about with the CONSUME_CLICK style and

overrode the onSavePrompt per RexDoug's suggestion as:

 

Protected boolean onSavePrompt() {

return true;

}

 

Problem solved.