0

我想从 Rss 提要为 lwuit 列表设置标题和图像,我可以设置标题,但我不知道如何设置图像?设置图像和标题后,我需要在表单上显示它。 ..这是我的代码:,帮助...

public void disp() {
          //String[] items={newsItem.getTitle()};
        for(int i=0;i<news.size();i++){


          newsItem=(News)news.elementAt(i);

         myNewsList.addItem(newsItem.getTitle().toString());
          System.out.println(newsItem.getTitle());


        }
        try{
                  System.out.println("hiii");

        form1.addComponent(myNewsList);

        form1.addCommand(cmdDetails);
        form1.setScrollable(true);
        form1.setTransitionInAnimator(Transition3D.createRotation(250, true));

          form1.show();
        }
        catch(Exception e){
            e.printStackTrace();
        }
4

1 回答 1

1

您可以使用列表渲染器在单个列表项中添加图像和文本。

NewsListRenderer.java

public class NewsListRenderer implements ListCellRenderer {

    private Label lblImage;
    private TextArea textAreaHeadline;

    public Component getListCellRendererComponent(List arg0, Object obj,
            int arg2, boolean isSelected) {

        Container newsContainer = new Container();
        newsContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));

        News newsListObj = (News) obj;
        Image img = newsListObj.getThumbnail();
        lblImage = new Label(img);
        lblImage.getStyle().setBgTransparency(0);
        lblImage.setTextPosition(Component.BOTTOM);
        newsContainer.addComponent(lblImage);

        textAreaHeadline = new TextArea(3, 25);
        textAreaHeadline.setSelectedStyle(textAreaHeadline.getStyle());
        textAreaHeadline.setText(newsListObj.getHeadLine());
        textAreaHeadline.setEditable(false);
        textAreaHeadline.getStyle().setBorder(null);
        textAreaHeadline.setFocusable(false);
        textAreaHeadline.getStyle().setBgTransparency(0);
        newsContainer.addComponent(textAreaHeadline);
        return newsContainer;
    }

    public Component getListFocusComponent(List arg0) {
        return new Container();
    }
}

新闻班成员:

1) 新闻标题 - getHeadLine() 检索标题。

2) 新闻图片 - getThumbnail() 检索图片。

    myNewsList = new List(news);
    myNewsList.setListCellRenderer(new NewsListRenderer());
    form1.addComponent(myNewsList); 
    form1.addCommand(cmdDetails);
    form1.setScrollable(true);
    form1.setTransitionInAnimator(Transition3D.createRotation(250, true));
    form1.show();
于 2012-08-06T09:06:26.003 回答