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");
}
}
}
}