07-22-2011 08:58 PM
I've been dealing with a few issues at the same time, and they seem to be at least partially related. I fixed the problem in the other thread I mentioned, so now I'm trying to focus on this.
Now that I've changed the buttons to extend ButtonField, the problem has changed.
ButtonA still works properly. The problem with clicking anywhere on my custom HorizontalFieldManager is also gone.
The problem is now that clicking on ButtonB does nothing.
I tested by putting identical buttons into the manager, and one works and the other doesn't.
Can I assume that this is a problem with my custom HorizontalFieldManager, and not the buttons themselves?
This is my manager:
import net.rim.device.api.ui.component.ButtonField; import net.rim.device.api.ui.container.HorizontalFieldManager; class BFHM extends HorizontalFieldManager { private ButtonField leftButton; private ButtonField rightButton; private final static int TOP_MARGIN = 5; private final static int LEFT_MARGIN = 5; public BFHM() { super( USE_ALL_WIDTH ); } public void sublayout( int maxWidth, int maxHeight ) { super.sublayout( maxWidth, maxHeight ); int width = getWidth(); if (rightButton != null ) { int x = width - rightButton.getWidth() - LEFT_MARGIN; int y = TOP_MARGIN; setPositionChild( rightButton, x, y ); } if (leftButton != null) { int y = TOP_MARGIN; int x = LEFT_MARGIN; setPositionChild( leftButton, x, y ); } setExtent( maxWidth, leftButton.getHeight() + TOP_MARGIN * 2 ); } public void setLeftButton( ButtonField leftButton ) { this.leftButton = leftButton; super.add(leftButton); } public void setRightButton( ButtonField rightButton ) { this.rightButton = rightButton; super.add(rightButton); } }
It simply places 2 buttons on either side of the field.
Any suggestions appreciated.
07-25-2011 12:20 AM
Hi,
This worked for me.
/*
* BFHM.java
*
* © <your company here>, 2003-2008
* Confidential and proprietary.
*/
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Field;
import net.rim.device.api.system.Display;
public class BFHM extends Manager {
private ButtonField leftButton;
private ButtonField rightButton;
private final static int TOP_MARGIN = 5;
private final static int LEFT_MARGIN = 5;
public BFHM() {
super( USE_ALL_WIDTH );
}
protected void sublayout(int width, int height) {
//set the left field
Field leftField = getField(0);
if (leftField != null && equals(leftField.getManager())) {
int y = TOP_MARGIN;
int x = LEFT_MARGIN;
layoutChild(leftField,width/3,height);
setPositionChild(leftField, x, y);
}
// start with the right Field
Field rightField = getField(1);
if (rightField != null && equals(rightField.getManager())) {
int x = width - rightField.getWidth() - LEFT_MARGIN;
int y = TOP_MARGIN;
layoutChild(rightField, width/3,height);
setPositionChild( rightField, x, y );
}
//To set the required dimensions for the field
setExtent(width,height);
}
}just add fields to this .
Thanks & Regards
pp
07-26-2011 12:10 AM
Excellent, thank you! I had something similar, but couldn't get layoutChild to seem to work properly, and I see now that it is needed.
One more quick question (more about style) if I may. I modified the setExtent() call to use a height just barely tall enough to give room for the buttons and the margins that I want. The example code you supplied caused the manager to take up the entire screen. Should I be supplying a value just large enough for what I need, or is there a better way to do it?
07-26-2011 12:27 AM
07-26-2011 11:38 PM
I knew that :-), I almost ashamed I asked!
Thanks for your help.
09-13-2011 08:31 AM
fwiw I came across this thread, also having problems with the wrong button responding to the touch.
In my case, the advice here and in other threads did not help. For me, the problem was that my buttons were in a custom manager I had made.
In my custom manager in the sublayout() method, I was calling super.sublayout(), and then laying out some special fields myself. The solution in my case was to NOT call super.sublayout() from my custom manager. That was the only change required - the buttons (button-styled custom fields) I used did not need updating.
I mention this in case it helps someone in the future with similar problem, since this seems to be a common question.