BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   what's wrong with this button? (http://www.blackberryforums.com/showthread.php?t=45172)

obijohn 08-29-2006 10:16 AM

what's wrong with this button?
 
Why does a single-item "close" menu appear when this button is clicked with the trackwheel but no menu appears when it is "clicked" by pressing ENTER when it has focus? If I add an edit field, the default main menu appears when the trackwheel is clicked in the edit field (which is what I want), but when the button defined below is clicked with the trackwheel that single-item "close" menu appears (which I DON'T want). What am I doing wrong with this button?

Code:

// ----- ButtonTestScreen.java ----------------------------------
package buttontest;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

public class ButtonTestScreen extends MainScreen {
       
    public ButtonTestScreen() { }

    public boolean onClose()
    {
        Dialog.alert("BYE!");
        System.exit(0);
        return true;
    }
   
}

Code:

// ----- ButtonTest.java ----------------------------------
package buttontest;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.system.*;

public class ButtonTest extends UiApplication implements FieldChangeListener
{
    private boolean clicked;
    private LabelField appTitle;
    private ButtonField testButton;
    private ButtonTestScreen mainScreen;
   
    public static void main(String[] args)
    {
        ButtonTest app = new ButtonTest();
        app.enterEventDispatcher();
    }
   
    public ButtonTest()
    {
        clicked = false;
        ButtonTestScreen mainScreen = new ButtonTestScreen();
        appTitle = new LabelField("Button Test");   
        testButton = new ButtonField("Click Me"); 
        testButton.setChangeListener(this);         
        mainScreen.setTitle(appTitle);
        mainScreen.add(testButton);
        pushScreen(mainScreen);
    }

    public void fieldChanged(Field field, int context)
    {
        if (field == testButton)
        {
            if(clicked)
            {
                clicked = false;
                testButton.setLabel("Click Me");
            }
            else
            {
                clicked = true;
                testButton.setLabel("Clicked");
            }
        }
    }   
   
}


jfisher 08-29-2006 10:43 AM

Try:

testButton = new ButtonField("Click Me", ButtonField.CONSUME_CLICK);

obijohn 08-29-2006 10:50 AM

Quote:

Originally Posted by jfisher
Try:

testButton = new ButtonField("Click Me", ButtonField.CONSUME_CLICK);

YES!! That was it, thanks!


All times are GMT -5. The time now is 10:31 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.