android - Access Recyclerview viewholder from activity -
i'm developing music player app android. when song completes send broadcast , in activity want change play/pause icon in row accordingly.
the activity receives broadcast of next song don't know how update row activity.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_now_playing); mstaggergridlayoutmanager = new staggeredgridlayoutmanager(1, staggeredgridlayoutmanager.vertical); mrecyclerview = (recyclerview) findviewbyid(r.id.now_playing_songs_list); mrecyclerview.setlayoutmanager(mstaggergridlayoutmanager); madapter = new listadapter(this, msonglist) mrecyclerview.setadapter(madapter); mreciever = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { if(intent.getaction().equals(musicservice.song_finished)) { //want change row icon here } } };
how access viewholder defined inside madapter in activity?
you must change model activity , ask adapter update view. single responsibility
1 of oop
design principles. example song objects must have boolean
value name isplaying
. when user playing song must set true
. when receive broadcast
find song list , set boolean
false
, call madapter.notifydatasetchanged()
. in getview
method check variable , set ui
pause or play state.
Comments
Post a Comment