简体   繁体   中英

Custom button field in blackberry

I am using a custom ButtonField in my application. I have used the code from the " Blackberry Custom Button Field " blog post on Coderholic to create a custom button in my app. Now I want to set the editable property to false for this custom button.

How do I do the equivalent of button.setEditable(false) for this custom button?

mybuttonid.setEditable(false) is not working.

Override Field.setEditable(boolean editable) to track your own custom editable boolean:

private boolean customEditable = true;

public void setEditable(boolean editable) {
    super.setEditable(editable);
    customEditable = editable;
    // invalidate(); forces paint(Graphics graphics) to be called
}

Override navigationClick(int status, int time) to use that boolean to detect whether to react on click events:

protected boolean navigationClick(int status, int time) {  
    if (customEditable) fieldChangeNotify(1);
    return true;
}

If you need a custom visual appearance for disabled state, then also override paint(Graphics graphics) to use another color. In this case you'll also need to call invalidate() from the setEditable() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM