我有一个Html字符串:
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=/"tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
我想在我的LWUIT表单屏幕上显示文本和图像,对于我的要求我使用了以下代码:
public class LwuitMidlet extends MIDlet {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, LWUIT!");
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=www.teluguone.com/tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
HTMLComponent com=new HTMLComponent();
com.setPreferredSize(new Dimension(300,300));
com.setHTML(html, null, null, false);
com.setShowImages(true);
//com.setHTML(image, null, null, false);
f.addComponent(com);
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
如果我使用上面的代码,我只能显示文字,但我无法显示图片,我已经测试了我的诺基亚SDK 2.O和SDK 3.0.5上的应用程序
任何人都可以帮助我吗?
答案 0 :(得分:2)
您需要拥有完整的HTML代码而不仅仅是一个代码段。 HTML,正文等。
答案 1 :(得分:0)
你的img标签上的src属性在开头缺少(“)字符。我没试过,但可以这样。
答案 2 :(得分:0)
您是否尝试使用
com.setBodyText(html);
代替
com.setHTML(html, null, null, false);
和。我正在使用LWUIT示例应用程序中的HttpRequestHandler实现(您可以获取示例应用程序:LWUITBrowser),而不是DefaultRequestHandler或null。
HttpRequestHandler handler = new HttpRequestHandler();
HTMLComponent com = new HTMLComponent(handler);
希望它有所帮助。