Skip to content

Instantly share code, notes, and snippets.

@deepak786
Last active January 11, 2017 10:20
Show Gist options
  • Save deepak786/a935f5cc00cf66b524e7 to your computer and use it in GitHub Desktop.
Save deepak786/a935f5cc00cf66b524e7 to your computer and use it in GitHub Desktop.
Use of Recycler Listener on ListView when the listItem is Recycled for later use. For example you can use this to stop playing audio or video when listitem becomes invisible like Facebook, Instagram, Twitter
yourListView.setRecyclerListener(new RecyclerListener() {
@Override
public void onMovedToScrapHeap(View view) {
// get the holder of the list item from where you can update ui, stop media player etc.
Holder holder = (Holder)view.getTag();
if(holder.mp!=null && holder.mp.isPlaying()){
holder.mp.pause();
holder.imageViewPlay.setBackgroundResource(R.drawable.icon_play);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment