web services - How to refresh the value of any object in previous stacked Activity's Adapter in android -
i working on music app in user getting mp3 file webservice api. when selecting song in adapter class, getting selectionpositions value , sending in next activity(playsong) using intent. in next activity having layout of music player starts playing song.
here adapter class.
public class albumnlistadapter extends baseadapter { context cxt; arraylist<albumnlistdata>arr; private mediaplayer mediaplayer; public textview songname, duration; private double timeelapsed = 0, finaltime = 0; private int forwardtime = 2000, backwardtime = 2000; private handler durationhandler = new handler(); private seekbar seekbar; public string st,satic; public string url; private int selectedposition; private static final string tag_messages = "messages"; public sharedpreferences sharedpreferences; string filenameee; public albumnlistadapter(context cxt,arraylist<albumnlistdata>arr) { this.cxt=cxt; this.arr=arr; } @override public int getcount() { return arr.size(); } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } @override public view getview(final int position, view convertview, viewgroup parent) { view v=convertview; if(v==null) { v=view.inflate(cxt, r.layout.songslistitem, null); } textview tvaudioname=(textview)v.findviewbyid(r.id.text1); linearlayout laysong = (linearlayout)v.findviewbyid(r.id.lvsong); tvaudioname.settext(arr.get(position).strgeneralid); sharedpreferences = cxt.getsharedpreferences(prefs_name, context.mode_private); satic ="http://sabakuch.org/public/uploads/tracks/"; laysong.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub filenameee = arr.get(position).strsongfileid; toast.maketext(cxt, filenameee, toast.length_short).show(); string playsongpath =satic+filenameee; intent =new intent(cxt,playsong.class); i.putextra("path", playsongpath); i.setflags(intent.flag_activity_new_task); cxt.startactivity(i); } }); return v; } }
here next activity in playing song.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //set layout of activity setcontentview(r.layout.songsplay); path =getintent().getextras().getstring("path"); name =getintent().getextras().getstring("name"); mediaplayer = mediaplayer.create(playsong.this, uri.parse(path)); finaltime = mediaplayer.getduration(); //initialize views initializeviews(); } public void initializeviews(){ b1 = (imageview) findviewbyid(r.id.backbutton); b3=(imageview)findviewbyid(r.id.playbutton); b4=(imageview)findviewbyid(r.id.nextbutton); if(index==0){ b3.setvisibility(view.visible); //b2.setvisibility(view.gone); }else if(index==1){ b3.setvisibility(view.gone); //b2.setvisibility(view.visible); } //mediaplayer = mediaplayer.create(this, uri.parse(path)); // finaltime = mediaplayer.getduration(); b3.setonclicklistener(new view.onclicklistener() { @suppresslint("newapi") @override public void onclick(view v) { index=1; changeimagebutton(); mediaplayer.start(); finaltime = mediaplayer.getduration(); } }); b1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { int temp = (int)starttime; if((temp+forwardtime)<=finaltime){ starttime = starttime + forwardtime; mediaplayer.seekto((int) starttime); toast.maketext(getapplicationcontext(),"you have jumped forward 5 seconds",toast.length_short).show(); } else{ toast.maketext(getapplicationcontext(),"cannot jump forward 5 seconds",toast.length_short).show(); } } }); b4.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { int temp = (int)starttime; if((temp-backwardtime)>0){ starttime = starttime - backwardtime; mediaplayer.seekto((int) starttime); toast.maketext(getapplicationcontext(),"you have jumped backward 5 seconds",toast.length_short).show(); } else{ toast.maketext(getapplicationcontext(),"cannot jump backward 5 seconds",toast.length_short).show(); } } }); } protected void changeimagebutton() { if(index==0){ b3.setvisibility(view.visible); }else if(index==1){ b3.setvisibility(view.gone); } } private runnable updatesongtime = new runnable() { public void run() { starttime = mediaplayer.getcurrentposition(); myhandler.postdelayed(this, 100); } }; @override public void onbackpressed () { if (mediaplayer != null) mediaplayer.stop(); super.onbackpressed(); } @override public void onpause () { if (mediaplayer != null) { mediaplayer.pause(); mediaplayer.stop(); } super.onpause(); }
}
i not having issue till now, when want change song. guess if able change selectedposition in previous adapter class, able next , previous song api. how can that?? please me. in advance.
i have resolved issue, logic behind clicked item in songlist in activity1 , selectedposition
. parse selected songlist
value in activity2. after got same songlist
in activity2 too. using for-loop, compared songlist
selectedposition
. this, got current value of selected item, set index in musicplayer. when select next , previous song, increase , decrease current index
, got item of current index.
Comments
Post a Comment