Many thanks to @cwbowron. Just to make it more clear, I have pasted my code here. We need to override two methods to make it work as expected:
onViewAttachedToWindow() is called when a view created by this adapter has been attached to a window.
onViewDetachedFromWindow() is called when a view created by this adapter has been detached from its window.
And this is what I needed. Below is my implementation:
public class RecyclerAdapterMessage extends RecyclerView.Adapter<RecyclerAdapterMessage.MessagesViewHolder> {
private Context mContext;
private ArrayList<ModelInboxFeed> modelInboxFeedArrayList;
private OnUserProfileClickListener mOnUserProfileClickListener;
public RecyclerAdapterMessage(Activity context, ArrayList<ModelInboxFeed> modelInboxFeedArrayList) {
...
}
/**
* Create new views (invoked by the layout manager)
*/
@Override
public RecyclerAdapterMessage.MessagesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card_normal, parent, false);
return new MessagesViewHolder(mContext, view);
}
/**
* Replace the contents of a view (invoked by the layout manager)
*/
@Override
public void onBindViewHolder(final RecyclerAdapterMessage.MessagesViewHolder holder, int position) {
...
}
/**
* Return the size of your data set (invoked by the layout manager)
*/
@Override
public int getItemCount() {
return modelInboxFeedArrayList.size();
}
public interface OnUserProfileClickListener {
void onUserProfileClick();
}
public class MessagesViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private WebView mWebView;
...
}
@Override
public void onViewDetachedFromWindow(MessagesViewHolder holder) {
super.onViewDetachedFromWindow(holder);
holder.mWebView.onPause();
}
@Override
public void onViewAttachedToWindow(MessagesViewHolder holder) {
super.onViewAttachedToWindow(holder);
holder.mWebView.onResume();
}
}
Hope it helps anyone with same requirement.
Happy Coding..!!