Question

I developed RssFeed Application using LWUIT j2me(java) for 2 xml files, now I want to show those 2 xml files on LWUIT Tabs.

That means, when my application runs, default tab will be displayed (on that tab my first Rss xml file Titles should be displayed), and when the user click on tab2 my second Rss xml titles should be displayed.

I am able to display the same titles of one rss files on both the tabs, how to control my flow to achieve my task?

Here my code:

public class XMLMidlet extends MIDlet implements ActionListener {

    public XMLMidlet() {
        Display.init(this);
        news = new Vector();
        m_backCommand = new Command("Back");

        cmdExit = new Command("EXIT");
        cmdDetails = new Command("Details");
    }

    public void startApp() {
    //RssFeed URL's     
   String urls[] = {"http://topnews-23.rss",
      "http://topstory-12.rss"};

  for(int i=0;i<urls.length;i++){
        ParseThread myThread = new ParseThread(this,urls[i]);
        //this will start the second thread
        myThread.getXMLFeed(urls[i]);
            }
    }

     //method called by the parsing thread

    public void addNews(News newsItem,String url) {
        try{
        news.addElement(newsItem);
        form1 = new Form();

        myNewsList = new List(newsVector);
        newsList    =new List(newsVector);
        myNewsList.setRenderer(new NewsListCellRenderer());
        newsList.setRenderer(new NewsListCellRenderer());

        tabs=new Tabs(Component.TOP);

        tabs.addTab("TopNews", myNewsList);

        tabs.addTab("Topstory",newsList);

        form1.addComponent(tabs);
        form1.show();
  }

        catch(Exception e){
       e.printStackTrace();     
}
}
Was it helpful?

Solution

You should move below code

myNewsList = new List(newsVector);
newsList    =new List(newsVector);
myNewsList.setRenderer(new NewsListCellRenderer());
newsList.setRenderer(new NewsListCellRenderer());
tabs=new Tabs(Component.TOP);
form1 = new Form();
tabs=new Tabs(Component.TOP);
tabs.addTab("TopNews", myNewsList);
tabs.addTab("Topstory",newsList);

from addNews method to constructor XMLMidlet. addNews method should use url parameter to differ for which list the newsItem is directed.

Update

Below is how I think you should implement addNews method:

public void addNews(News newsItem, String url) { 
  if (url.endsWith("topnews-20.rss")) {
    myNewsList.addElement(newsItem);
  } else if (url.endsWith("topstory-25.rss")) {
    newsList.addElement(newsItem);
  }
}

serRenderer does not need to be called from addNews and form1.show() should be moved to startApp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top