Java me 如何在lwuit表单屏幕中识别列表项?
我无法显示特定于在form1屏幕上单击的标题用户的详细表单信息,当我在form1屏幕上单击任何itemlist时,我只能显示第一个项目的详细信息(在我的代码中int index=myNewsList.getSelectedIndex()始终以0作为值返回) 下面是我的Rss应用程序的详细代码:Java me 如何在lwuit表单屏幕中识别列表项?,java-me,lwuit-form,Java Me,Lwuit Form,我无法显示特定于在form1屏幕上单击的标题用户的详细表单信息,当我在form1屏幕上单击任何itemlist时,我只能显示第一个项目的详细信息(在我的代码中int index=myNewsList.getSelectedIndex()始终以0作为值返回) 下面是我的Rss应用程序的详细代码: //method called by the parsing thread public void addNews(N
//method called by the parsing thread
public void addNews(News newsItem) {
newsVector.addElement(newsItem);//initialsed list with vector
myNewsList = new List(newsVector);
myNewsList.setListCellRenderer(new NewsListCellRenderer());
form1.addComponent(myNewsList);
form1.show();
myNewsList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int selectedIndex = myNewsList.getSelectedIndex();
if(selectedIndex != -1){
newsItem1 = (News)news.elementAt(selectedIndex);
Label l=new Label();
l.setText(newsItem1.getPubDate());
Form detailedForm=new Form();
detailedForm.addCommand(m_backCommand);
detailedForm.addCommandListener(this);
detailedForm.addComponent(l);
detailedForm.show();
}
}
});
}
Can you help?
将操作侦听器添加到列表中。仅当您单击列表中的任何项目时,才会调用它。在该操作侦听器中,获取所选项目并将其强制转换为新闻类对象,因为您在列表中添加了新闻类对象。从该对象获取唯一属性,如news id。使用当前表单对象(form1)将其传递到另一个屏幕 使用新闻id,您可以在另一个屏幕中显示相关数据。向其添加back命令。在back命令中,只显示form1对象
public void displayCompleteNewsScreen(Form form1,int newsid){
// Get the related data and add it to another form object(form2).
form2.addCommand("Back");
form2.addCommandListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
form1.show();
}
});
form2.show();
}
而不是使用
int selectedIndex = myNewsList.getSelectedIndex();
if(selectedIndex != -1){
newsItem1 = (News)news.elementAt(selectedIndex);
}
使用下面的代码
newsItem1 = (News)myNewsList.getSelectedItem();
在form2对象中,我想添加发布日期和一些描述,然后我想显示我的详细表单,例如(PubDate:Tue,o7 aug和description:Some text here from News对象)?我在allNewsClassObjs对象中已经有了发布日期和描述值,但是如何在form2上显示它呢?我使用的标签是pubdate=new Label();setText(detailNews.getPubDate());表格2.添加组件(发布日期);表格2.addCommand(m_backCommand);,正确的方法是什么?另外,我想在我的详细表单上显示段落文本和带有标题(描述:像这样)的发布日期,如果我这样使用,Label pubdate=new Label();setText(detailNews.getPubDate());表格2.添加组件(发布日期);表格2.addCommand(m_backCommand);,我无法显示标题,只能显示带点的单行文本……?使用TextArea显示段落文本。让我们Hii kalai,我已经更改了代码,工作正常……这里是我的代码。。。public void actionPerformed(ActionEvent ae){List source=(List)ae.getSource();try{News selectedNewsItem=(News)source.getselectedEdItem();System.out.println(“selectedIndex”+selectedNewsItem.getDescription());if(selectedNewsItem!=null){displayCompleteNewsScreen(selectedNewsItem);
newsItem1 = (News)myNewsList.getSelectedItem();