How do I remove focus from an LWUIT textbox and resize the form correctly when the virtual keyboard is hidden?
I am having a problem with LWUIT Textbox .
In some of my forms, I show the CategoryBar , and in others I hide it.
In some Forms I have Text Fields , the problem occurs when I focus on one and create a Virtual Keyboard (VKB). When VKB appears , the screen components resize to accommodate the Textbox to be visible while I am typing, but when I hide VKB , either with the Back button or with the VKB return key , the Textbox remains focused , not just when the screen components change, the currently visible Form is resized as if there were no CategoryBar , so any components located at the bottom of the Form, CategoryBar are hidden .
This is captured by displaying another Form (which includes PopupChoiceGroup and DatePicker ) and then returning to the Form , which is covered by the CategoryBar .
In other forms where the CategoryBar is not displayed , sometimes resizing when VKB is displayed causes the forms to resize as if CategoryBar >, allowing interaction with it when it shouldn't be available.
How can I make sure that focus is completely lost in the Textbox ? Also, how to make sure the form is resized correctly, is the CategoryBar visible ?
EDIT
I dug up the class reference for TextField , Form and VKB . Subsequently I found the autoAdjust method, which according to the documentation:
Automatic adjustment of the size of the dialog box. This method is fired from the sizeChanged event.
The sizeChanged method sounded like something I should check, and in the form, a link to the description of this method:
This method is only called when the main canvas for the form receives a resized event. This method will trigger the relay of the Form. This method will receive a callback only if this form is the Current Form
This method looked like the resize callback that I was looking for, so I tried it and put a NotificatioBar to display the width and height values ββsent when the method was called.
What I discovered after testing this on my device was that when the form resized after showing or hiding the VKB , the height value was sometimes instead of 270 (the height for the form when the CategoryBar is displayed ) which was sent as 320 (the full screen height as if there were no CategoryBar ).
Until now, I couldn't figure out why the form is ignoring the fact that the CategoryBar is displayed or not when resizing itself.
I tried to change the height of the form inside the sizeChanged method, but it was not affected by the Form . It seems to me what I need to change is the canvas the form is drawn on, but I don't know for sure since the canvas is hidden in LWUIT.
Could it be the canvas my Form is drawing on is a bug? What triggers this behavior?
source to share
At the moment I have found a workaround to avoid my components being hidden by the CategoyBar because the form was changed incorrectly after VKB was hidden, for a scenario where the form is changed incorrectly and displays a CategoryBar (which I don't know why is displayed if I call its setVisibility method and pass false).
I first tried the sizeChanged method:
protected void sizeChanged(int w, int h){
if(h > 270){
mainContainer.getStyle().setMargin(Component.BOTTOM, 50);
}
else{
mainContainer.getStyle().setMargin(Component.BOTTOM, 0);
}
}
I am checking the height value, if the value is greater than the expected height when displaying the CategoryBar then I set the bottom of my container to 50 so it will be visible.
But that was not enough, because if I show the same form again and it is resized correctly, the Container stays with a bottom of 50. So I overridden the onShow method too:
protected void onShow(){
int containerBottom = mainContainer.getStyle().getMargin(Component.BOTTOM);
if(this.getHeight() == 270 && containerBottom == 50){
mainContainer.getStyle().setMargin(Component.BOTTOM, 0);
}
}
I needed to make sure the height is 270 and the bottom of the container is 50 and the bottom of the container is 0.
Since I haven't found a way to avoid changing the form and showing the CategoryBar when it doesn't show at all, I don't consider myself a complete answer. Will be updated if I find a workaround for this.
EDIT
I tried to explicitly set the displayed / hidden status by calling the setVisibility method inside the onShow method for each form . So far, I have managed to avoid the visual problems I experienced earlier. I'm not sure if this issue was caused by LWUIT or J2ME limitations, but this is how I worked on it.
source to share