05-17-2012 09:13 AM
I need make two buttons.
-first button at the left side of the display
-second button at the right side of the display
i try make like this but it dosn't work(
HorizontalFieldManager titleHFM = new HorizontalFieldManager(HorizontalFieldManager.FIEL
HorizontalFieldManager leftHFM = new HorizontalFieldManager(HorizontalFieldManager.FIEL
leftHFM.add(new ButtonField("Left"));
HorizontalFieldManager rightHFM = new HorizontalFieldManager(HorizontalFieldManager.FIEL
rightHFM.add(new ButtonField("Right",ButtonField.RIGHT));
titleHFM.add(leftHFM);
titleHFM.add(rightHFM);
add(titleHFM);
Solved! Go to Solution.
05-17-2012 09:54 AM - edited 05-17-2012 09:55 AM
Welcome to the forums.
I recommend that you use the EvenlySpacedHorizontalFieldmanager or HorizontalButtonFieldSet from here:
05-17-2012 09:56 AM
Hi,
You can get this by overridng sublayout of the title manager and no need to take seperate manager for each and every button.
Try like this,
HorizontalFieldManager titleHFM = new HorizontalFieldManager(HorizontalFieldManager.FIEL
{
protected void sublayout(int maxWidth, int maxHeight)
{
setPositionChild(getField(0), 0, 0);
layoutChild(getField(0), getField(0).getPreferredWidth(),getField(0).getPre
setPositionChild(getField(1), Display.getWidth() - getField(1).getPreferredWidth(), 0);
layoutChild(getField(1), getField(1).getPreferredWidth(),getField(1).getPre
setExtent(maxWidth, maxHeight);
}
};
titleHFM.add(new ButtonField("Left"));
titleHFM.addnew ButtonField("Right");
Regards,
Lakshman K
05-17-2012 10:12 AM
I recommend you look at the code supplied in the KB article I previously pointed you at and use that code. The samples supplied are well written and demonstrate best practice.
Unfortunately the example given above by lakshman9687 has a number of issues. For example, the last line
setExtent(maxWidth, maxHeight);
will grab the maximum amount of space for the Manager, in fact it only needs enough height for the two buttons.