Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Blackberry Rss Parsing java

I developed Rss Feed application,in this i am able to retrieve titles from RssFeed and successfully displayed titles on myscreen,my requirement is i want to retrieve image tag value from Rss and i want to display list with images,for title to get value from rss i have used one vector listelements,but how to retrieve image tag value using single vector?

 

public class xmlparsing extends UiApplication implements ListFieldCallback, FieldChangeListener
{

public static void main(String[] args)
{
System.out.println("Start of main method");
xmlparsing app = new xmlparsing();
app.enterEventDispatcher();
}


public long mycolor ;
Connection _connectionthread;
private static ListField _list;
private static Vector listElements = new Vector();
public MainScreen screen = new MainScreen();

VerticalFieldManager mainManager;
VerticalFieldManager subManager;
int selectedList;


public xmlparsing()
{
super();
pushScreen(screen);

final Bitmap backgroundBitmap = Bitmap.getBitmapResource("background.jpg");

mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
{

public void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, Display.getWidth(),Display.getHeight(),backgroundBitmap, 0, 0);

super.paint(graphics);
}

};

subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
{
protected void sublayout( int maxWidth, int maxHeight )
{
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();

super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};


screen.add(mainManager);


_list = new ListField()

{
protected boolean navigationClick(int status, int time)
{
}
public void paint(Graphics graphics)

{
graphics.setColor((int) mycolor);
super.paint(graphics);

}

};
mycolor = 0x00FFFFFF;
_list.invalidate();
_list.setEmptyString("* Feeds Not Available *", DrawStyle.HCENTER);
_list.setRowHeight(50);
_list.setCallback(this);
mainManager.add(subManager);
listElements.removeAllElements();
_connectionthread = new Connection();
_connectionthread.start();
}

 

 


private class Connection extends Thread
{
public Connection()
{
super();
}

public void run() {
Document doc;
StreamConnection conn = null;
InputStream is = null;
try {

conn = (StreamConnection) Connector.open("http://toucheradio.com/toneradio/android/toriLite/toriplaylist.xml"+";deviceside=true");

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setIgnoringElementContentWhitespace(true);
docBuilderFactory.setCoalescing(true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
docBuilder.isValidating();
is = conn.openInputStream();
doc = docBuilder.parse(is);
doc.getDocumentElement().normalize();
NodeList list = doc.getElementsByTagName("title");
for (int i = 0; i < list.getLength(); i++) {
Node textNode = list.item(i).getFirstChild();
listElements.addElement(textNode.getNodeValue());
}
/*NodeList list = doc.getElementsByTagName("image");
for (int i = 0; i < list.getLength(); i++) {
Node textNode = list.item(i).getFirstChild();
listElements.addElement(textNode.getNodeValue());
}
*/

} catch (Exception e) {
System.out.println(e.toString());
} finally {
if (is != null) {
try { is.close();
} catch (IOException ignored) {}
} if (conn != null) {
try { conn.close(); }
catch (IOException ignored) {}
} } UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
_list.setSize(listElements.size());

subManager.add(_list);


screen.invalidate();
}
});
}

}


public void drawListRow(ListField list, Graphics g, int index, int y, int w)
{
String tes = (String)listElements.elementAt(index);
int yPos = 0+y;
g.drawLine(0, yPos, w, yPos);
g.drawText(tes, 5, 15+y, 0, w);
}


public Object get(ListField list, int index)
{
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String prefix, int string)
{
return listElements.indexOf(prefix, string);
}
public int getPreferredWidth(ListField list)
{
return Display.getWidth();
}
public void insert(String toInsert, int index) {
listElements.addElement(toInsert);
}

public void fieldChanged(Field field, int context) {

 


}
}

 

Developer
Posts: 16,846
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Blackberry Rss Parsing java

you have to detect the image links in the text and download them asynchronically.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Re: Blackberry Rss Parsing java

for the image,can i have to create separate ListFiled,like titles?i am not getting ?how can i add my list with images and titles ?