I am trying to use native components in a LWUIT app on Android platform.
private Component createNativeTextEdit() {
final Object[] result = new Object[1];
AndroidImplementation.runOnAndroidUIThreadAndWait(LWUITActivity.currentActivity, new Runnable() {
@Override
public void run() {
EditText nativeView = new EditText(LWUITActivity.currentActivity);
nativeView.setText("Type here..");
result[0] = PeerComponent.create(nativeView);
}
});
return (Component)result[0];
}
I then place a component inside a form:
mMainForm = new Form();
mMainForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
mMainForm.addComponent(createNativeTextEdit());
mMainForm.show();
Then I get an "IllegalArgumentException: width and height must be > 0" when the system tries to draw the new form.
I traced the problem down to the call to AndroidImplementation.PeerWrapper.getBuffer() and the values returned by getWidth() and getHeight() are width=474 and height=0.
How is height supposed to be set? What am I missing?
Do you know of a working sample program that uses PeerComponent on Android? I searched the web but could only find some snippets where it is not clear where the code is called from, which thread it is executed on etc.
Thanks.
I figured out the issue.
I am using LWUIT 1.5 thorsten_s port for Android.
The issue is that LWUIT computes components preferred size before the native view is added so both width and height are set to 0.
The way to fix it is to call View.measure() on the PeerWrapper at creation time to initialize it to preferred size.
Inside AndroidImplementation.java at the end of the constructor for PeerWrapper class add the line:
This completely fixes the problem. I can now use components like AnalogClock, DatePicker, and native EditText in LWUIT forms.