android display image on specific row of listview -
i have listview containing 25 different items. when click on item, corresponding sound file gets added array, starting index 0 of course, , more items selected, each corresponding sound file gets added next index of array. so, when play button pressed, sound file associated index 0 plays, sound index 1, , on until there no more indexes. little bit of (possibly unnecessary) background info, how add image listview of item playing? ipod, want display icon on right hand side on row of playing sound. have icon, , can display it, i'm not sure how tell on row display, based on sound/array index playing. have read different tutorials on adding images listviews, nothing adding 1 image specific row.
to solve problem, think may need implement own subclass of baseadapter overriding abstract methods. simpleadapter , simplecursoradapter, new adapter bind data( sound file in case) list, baseadpater should capable of finding kind of view should appear in each position of list, , capable of generating proper list view item.
you need override methods of baseadapter meet needs. important followings:
int getviewtypecount();
in case, list contains 2 kinds of item: playing or not in playing, method should return 2.
int getitemviewtype(int position);
you need put logic here check if sound file @ parameter position playing? if item @ position playing, should return constant int type_playing, otherwise return type_nonplaying(of course need define these constants ahead).
view getview(int position, view convertview, viewgroup parentview);
this method has todos, think can following steps below:
find type of item @ position, either type_playing or type_nonplaying
get instance of layoutinflater inflate different layout file 2 different type of item, type_playing item should include image indicate item's corresponding file in playing. note need context variable retrieve layoutinflater. can declare context member in adapter , initialize in constructor of adapter.
bind other information of each file: file name, time length, etc.
if playing file changed clicking list item or other interaction, don't forget call baseadapter's notifydatasetchanged() method refresh list.
may helps.
Comments
Post a Comment