java - getView is never called for reasons beyond me -


i have custom list view adapter populated through asynctask, i'm calling notifydatasetchanged in onprogress function, , getcount() returns 10, yet list never shows, ive set breakpoint , determined getview() never called. ideas? ive tried hours , im stumped. ive done same thing in activity except 1 used viewholders, 1 holds text based data didn't bother.

adapter:

@override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; if(row == null) { row = inflater.inflate(r.layout.podcastepisode, null); } podcastitem item = items.get(position); textview episodetitle = (textview)row.findviewbyid(r.id.episodetitle); textview episodedate = (textview)row.findviewbyid(r.id.episodedate); episodetitle.settext(item.title); episodedate.settext(api.formatpodcastdate(item.date)); return row; } 

my task:

protected void onprogressupdate(podcastitem... progress) { addpodcastactivity.episodes.add(progress[0]); addpodcastactivity.adapter.notifydatasetchanged(); } 

i'd recommend moving list adapter inside activity file it's own file, , using this:

import java.util.arraylist; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; public class episodearrayadapter extends baseadapter { public episodearrayadapter(context context) { mcontext = context; items = new arraylist<podcastitem>(); } private context mcontext; private arraylist<podcastitem> items; public void add(podcastitem item) { items.add(item); notifydatasetchanged(); } public void remove(int index) { items.remove(index); notifydatasetchanged(); } public void clear() { items.clear(); notifydatasetchanged(); } @override public int getcount() { return items.size(); } @override public object getitem(int position) { return items.get(position); } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; if(row == null) row = layoutinflater.from(mcontext).inflate(r.layout.podcastepisode, null); podcastitem item = items.get(position); textview episodetitle = (textview)row.findviewbyid(r.id.episodetitle); textview episodedate = (textview)row.findviewbyid(r.id.episodedate); episodetitle.settext(item.title); episodedate.settext(api.formatpodcastdate(item.date)); return row; } } 

this type of code use list adapters in boid :) also, notice add/remove/clear functions call notifydatasetchanged(), makes don't have call when adding items.

when initialize it, use:

episodearrayadapter adapter = new episodearrayadapter(this); listview.setadapter(adapter); 

adding items add() function cause list update immediately. make sure call setadapter list view that's using adapter, otherwise there won't connection , nothing show in list (didn't see call in code).


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -