1

我有一个 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 上测试了我的应用程序

谁能帮我?

4

3 回答 3

2

您需要拥有完整的 HTML 代码,而不仅仅是片段。HTML、正文等

于 2012-10-24T16:58:37.680 回答
0

您在 img 标签上的 src 属性在开头缺少 (") 字符。我没有尝试过,但这可以是它。

于 2012-10-13T18:55:02.283 回答
0

你有没有尝试使用

 com.setBodyText(html);

反而

 com.setHTML(html, null, null, false);

和。我正在使用 LWUIT 示例应用程序中的 HttpRequestHandler 实现(您可以获取示例应用程序:LWUITBrowser),而不是 DefaultRequestHandler 或 null。

HttpRequestHandler handler = new HttpRequestHandler();
HTMLComponent com = new HTMLComponent(handler);

希望能帮助到你。

于 2013-10-25T09:49:20.123 回答