android - onCreateView ListView is Empty. Items Missing -
resolved. see singularhum's answer below.
i have sliding menu option points fragment. fragment inflates layout using oncreateview. update values of list in onactivitycreated . here source.
my listview 
public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { this.dateformat = new simpledateformat("dd/mm/yyyy hh:mm", locale.getdefault()); this.portfolio = new portfolio(); this.portfolio.addcompanynoupdate("yhoo"); // specify fragment layout file fragment class view view = inflater.inflate(r.layout.fragment_stock, container, false); progresstext = (textview) view.findviewbyid(r.id.progresstextview); // assign our cursoradapter adapter = new quoteadapter(getactivity(), portfolio.getquotes()); listview list = (listview) view.findviewbyid(r.id.list); list.setadapter(adapter); adapter.notifydatasetchanged(); return view; } then have onactivitycreated doing update.
public void onactivitycreated(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.update(); } my update class
private void update() { // if network connection available, update stock information if (utils.isnetworkavailable(getactivity())) { // start custom task downloads data on thread ui not lock new updatequotestask().execute(portfolio); } else { // otherwise display error message user this.progresstext.settext(this.getresources().getstring(r.string.no_internet_connection)); } } my adapter
public class quoteadapter extends baseadapter { private context context; private list<quote> quotes; public quoteadapter(context c, list<quote> quotes) { this.context = c; this.quotes = quotes; } public void addquote(quote q) { this.quotes.add(q); } @override public int getcount() { return this.quotes.size(); } @override public object getitem(int position) { return this.quotes.get(position); } public long getitemid(int position) { // can return default value adapter return 0; } @override public view getview(int position, view convertview, viewgroup parent) { miniquoteview miniquoteview = new miniquoteview(this.context, this.quotes.get(position)); miniquoteview.setlayoutparams(new listview.layoutparams(listview.layoutparams.fill_parent, listview.layoutparams.wrap_content)); return miniquoteview; } public void removeitem(int position) { this.quotes.remove(position); } } and xml standard listview
<relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <textview android:id="@+id/progresstextview" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/none" /> <listview android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:verticalspacing="2dp" android:layout_below="@+id/progresstextview" /> </relativelayout> for reason listview turns out empty. see image. can see debugger has values adapter. 
here related miniquoteview class , xml
i believe issue in filldata method in miniquoteview class.
your first if statement is:
if (this.quote == null) but not have else or else if statement when quote object not null.
then if @ second if statement (which reads quote data , sets views) inside first one, is:
if (this.quote.name != null) which never true because quote null within if. why not seeing in list view because nothing being set displayed.
so should this:
if (this.quote == null) { // displaying not available message } else if (this.quote.name != null){ // code display data }
Comments
Post a Comment