If you use Intent
and pass your data it will create new activity, what you can do is create an interface in your adapter as follows.
public interface GetSongCallBack {
void getSongNumber(int songNumber);
}
When you initialize your CustomAdapter
in activity, pass an instance of this interface.
Which will look like this :
CustomAdapter adapter = new CustomAdapter(..., new CustomAdapter.GetSongCallBack() {
public void getSongNumber(int songNumber) {
// do something here...
}});
Finally, whenever you want your activity to know that song has changed, call getSongNumber()
this method.
You can do it like this,
In the CustomAdapters constructor you are getting instance of interface so,
Declare a global variable :
GetSongCallBack callback;
Also add this line in the constructor,
public CustomAdapter(... ,GetSongCallBack callback) {
.
.
this.callBack = callBack;
}
And calling method goes like this,
callBack.getSongNumber(song);