android - ListView not displaying anything in new activity using array adapter -
i've got class should, theoretically, display rss headlines, single rss feed site, in listview called searchlistview
. if listview empty textview appears informing user listview empty, happens every time navigate activity. button , edittext filtering headlines.
i've got exact same class in project (this class main activity in said project) works fine.
rssitem class parses rss feed information headline title , url headline.
note: searchactivity not main activity.
edit: i'm using callback , loadermanager in main activity display items in list view well. i'm not knowledgeable these , don't know if might causing issue due main activity. not pass information main activity, though.
fixed: wasn't getting errors or but, reason, nothing displayed. went android manifest , realised app doesn't have permissions connect internet. silly mistake, easy miss.
<uses-permission android:name="android.permission.internet"/>
searchactivity.java
public class searchactivity extends appcompatactivity implements loadermanager.loadercallbacks<list<rssitem>> { private edittext medittext; private button mbutton; private arrayadapter<rssitem> madapter; private listview mlistview ; // hard wire rss feed source time being private string mdatasource = "http://feeds.bbci.co.uk/news/uk/rss.xml"; // no search string @ moment private string msearchstring = ""; private static final int loader_id = 1; // callbacks through interact loadermanager. private loadermanager.loadercallbacks<list<rssitem>> mcallbacks; private loadermanager mloadermanager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_search); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); mbutton = (button) findviewbyid(r.id.button); medittext = (edittext)findviewbyid(r.id.edittextsearch); madapter = new arrayadapter<>(this, android.r.layout.simple_list_item_1); mlistview = (listview)findviewbyid(r.id.searchlistview); mlistview.setadapter(madapter); textview emptytext = (textview)findviewbyid(r.id.textviewempty); mlistview.setemptyview(emptytext); // set list view item click listener mlistview.setonitemclicklistener(new listlistener(this)); // activity (which implements loadercallbacks<cursor> // interface) callbacks object through interact // loadermanager. loadermanager uses object // instantiate loader , notify client when data made // available/unavailable. mcallbacks = this; // initialize loader id '1' , callbacks 'mcallbacks'. // if loader doesn't exist, 1 created. otherwise, // created loader reused. in either case, // loadermanager manage loader across activity/fragment // lifecycle, receive new loads once have completed, // , report new data 'mcallbacks' object. mloadermanager = getloadermanager(); mloadermanager.initloader(loader_id, null, mcallbacks); } // handler search button click public void onclick(view v){ msearchstring = medittext.gettext().tostring(); mloadermanager.restartloader(loader_id, null, mcallbacks); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public loader<list<rssitem>> oncreateloader(int id, bundle args) { rssloader loader = new rssloader( this, // context mdatasource, // url of rss feed msearchstring // search loaded rssitem match in title ); return loader; } @override public void onloadfinished(loader<list<rssitem>> loader, list<rssitem> data) { madapter.clear(); madapter.addall(data); } @override public void onloaderreset(loader<list<rssitem>> loader) { madapter.clear(); } }
listlistener.java
public class listlistener implements onitemclicklistener { // , reference calling activity // calling activity reference activity mparent; /** set references in our constructor.*/ public listlistener(activity parent) { mparent = parent; } /** start browser url rss item.*/ public void onitemclick(adapterview<?> parent, view view, int pos, long id) { // create intent going display data intent = new intent(intent.action_view); // have set data our new intent; i.setdata(uri.parse(((rssitem)(parent.getitematposition(pos))).getlink())); // , start activity our intent mparent.startactivity(i); } }
i wasn't getting errors or but, reason, nothing displayed. went android manifest , realised app doesn't have permissions connect internet. silly mistake, easy miss.
<uses-permission android:name="android.permission.internet"/>
missing.
Comments
Post a Comment