How to controll flow of multiple Rss Files
Hii
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();
}
}
Re: How to controll flow of multiple Rss Files
You can instantiate Form, Tabs and List in startApp() method as below
[QUOTE]
private List myNewsList[];
private int i=0;
public void startApp() {
form1 = new Form();
tabs=new Tabs(Component.TOP);
myNewsList= new List[2];
//RssFeed URL's
String urls[] = {"http://topnews-23.rss",
"http://topstory-12.rss"};
for(;i<urls.length;i++){
ParseThread myThread = new ParseThread(this,urls[i]);
//this will start the second thread
myThread.getXMLFeed(urls[i]);
}
form1.addComponent(tabs);
form1.show();
}[/QUOTE]
And the addNews() method call should look like below:
[QUOTE]public void addNews(News newsItem,String url) {
try{
news.addElement(newsItem);
myNewsList[i] = new List(newsVector);
myNewsList[i].setRenderer(new NewsListCellRenderer());
if(i==0){
tabs.addTab("TopNews", myNewsList[i]);
} else{
tabs.addTab("Topstory", myNewsList[i]);
}
}
catch(Exception e){
e.printStackTrace();
}
}[/QUOTE]
Re: How to controll flow of multiple Rss Files
here the answer:
we 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.