android get rssitem description from listview -
in android app i'm using listview populated rssitems taken webpage url; listview shows me title , pubdate of rssitem.
realize when click on rssitem of listview, app shows me alert dialog showing me in message box descritpion of rssitem title.
how can realize it?
here code:
public class mainactivity extends actionbaractivity{ private listview listview; url url = null; rssfeed feed = null; alertdialog.builder alert; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); listview = (listview) findviewbyid(r.id.listview); alert = new alertdialog.builder(mainactivity.this); try { url = new url("http://www.unikore.it/index.php/ingegneria-informatica-home?format=feed"); } catch (malformedurlexception e) { e.printstacktrace(); } new readrsstask().execute(url); } private class readrsstask extends asynctask<url, void, rssfeed> { @override protected rssfeed doinbackground(url... params) { rssfeed result = null; url url = params[0]; if (!textutils.isempty(url.tostring())) { try { result = rssreader.read(url); } catch (saxexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } return result; } @override protected void onpostexecute(rssfeed result) { if (result != null) { arraylist<rssitem> rssitems = (arraylist<rssitem>) result.getrssitems(); arraylist<string> arraylist = new arraylist<string>(); (final rssitem rssitem : rssitems) { arraylist.add(rssitem.gettitle()+"\n"+rssitem.getpubdate()+"\n"); arrayadapter<string> lista = new arrayadapter<string>(getbasecontext(),android.r.layout.simple_list_item_1,arraylist); listview.setadapter(lista); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position,long id) { alert.settitle(listview.getitematposition(position).tostring()); alert.setmessage(); //here should set rssitem.getdescription() alert.show(); } }); log.i("rss reader", rssitem.gettitle()); } } } } }
you need change here
alert.show();
to
alertdialog dialog = alert.create(); // missed dialog.show():
edit:
remove loop , move oncreate()
after asynctask executed.
listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position,long id) { alert.settitle(listview.getitematposition(position).tostring()); alert.setmessage(rssitems.get(position).getdescription()); //here should set rssitem.getdescription() alert.show(); } });
make arraylist<rssitem> rssitems
public static , use
rssitems = (arraylist<rssitem>) result.getrssitems();
Comments
Post a Comment