Edit Field and Bitmap Image in the same horizontal field manager in Blackberry
I am building a small Blackberry app in which I have to add an editField and Bitmap Image One after another in a single Horiziontal field Manager. The code works fine when I am placing Bitmap Image before the EditField but when I am placing the Image after the EditField, Its not working properly.
开发者_如何学CHere is the code that I am using:
hfm1=new HorizontalFieldManager();
Bitmap image = Bitmap.getBitmapResource("search_icon.png");
BitmapField imageButton = new BitmapField(image, BitmapField.FOCUSABLE)
{
protected boolean navigationClick(int status, int time)
{
// This is method will invoke after clicking the image
// System.out.println("Image Clicked");
SearchButtonClick();
return true;
}
};
searchEdit=new EditField("",_DEFAULT_FIELD_TXT, 50, EditField.FIELD_LEFT|EditField.NO_NEWLINE){
public void layout(int width, int height)
{
Font font = getFont();
int _fieldHeight = font.getHeight()+5;
//int _fieldWidth = (getWidth()-100);
setExtent(300, _fieldHeight);
super.layout(width,height);
}
};
add(new SeparatorField());
searchEdit.setFont(MainAppScreen.fontTitle);
searchEdit.setMargin(1, 2,1,1);
//hfm1.setMargin(2,5,2,5);
hfm1.add(searchEdit);
hfm1.add(imageButton);
add(hfm1);
Please suggest. Also suggest some way for the proper alignment of components in the layout manager .
Here's a blog that talks about table layout. I think it's something you should consider. It gives you greater control over your layout.
As for your code above, I would guess that there isn't enough space to the right of the textbox to display the bitmap. I think if you start with the bitmap, it will show the entire bitmap and as much of the text field as it can. If you start with the text field it shows the entire field and has no room to show the bitmap (it won't show a partial bitmap, perhaps?)
I believe you'll have to shrink down your widths.
精彩评论