如何在同一表单上正确使用选取器和BrowserComponent



我需要在同一表单上同时使用选取器浏览器组件

Picker将允许用户选择一个值,该值用于生成将由BrowserComponent显示的HTML。

以下代码在Android上运行良好。

在iOS上,在使用选择器选择值后,一切都会变得一团糟:选择器仍在屏幕上绘制,BrowserComponent为空,应用程序挂起!?

代号一中的错误?

该问题在iOS 10、10.3.3和12.1 上是可复制的

package edu.ch.emf.praesto;
import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.ui.BrowserComponent;
import com.codename1.ui.CN1Constants;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.spinner.Picker;
public class App {
private Form currentForm;
private Resources theme;
public void init(Object context) {
// Loading the theme
this.theme = UIManager.initFirstTheme("/theme");
}
public void start() {
// Load last shown form on reopening
if (this.currentForm != null) {
this.currentForm.show();
return;
}
// Force orientation locking if the plattform supports it
if (Display.getInstance().canForceOrientation()) {
Display.getInstance().lockOrientation(true);
}
Form form = new Form(new BorderLayout());
String[] strs = new String[]{"Option 1", "Option 2", "Option 3"};
Picker picker = new Picker();
picker.setType(CN1Constants.PICKER_TYPE_STRINGS);
picker.setStrings(strs);
form.add(BorderLayout.NORTH, picker);
BrowserComponent htmlViewer = new BrowserComponent();
htmlViewer.setPage("<html><head></head><body><h1>Test</h1></body></html>", null);
form.add(BorderLayout.CENTER, htmlViewer);
form.show();
}
public void stop() {
this.currentForm = getCurrentForm();
if (this.currentForm instanceof Dialog) {
((Dialog) this.currentForm).dispose();
this.currentForm = getCurrentForm();
}
}
public void destroy() {
}
}

使用Picker.setDefaultUseLightweightPopup(true)强制选择器使用Java呈现的实现,而不是iOS中的flaky实现。

不幸的是,这可能会使Android上的选择器表现得像iOS选择器,这并不是所有情况下的最佳选择。所以你可以试着把安卓排除在这个逻辑之外。

最新更新