我想从Rss Feed设置标题和图像到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();
}
答案 0 :(得分: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();