I have an adapter that draws a string and a picture. This adapter is now used 5 fragments.
I read somewhere that the adapter should not be tied to a class. The adapter must carry in its name only what it does.
Therefore, I think it would be wrong to create for each fragment or activate your adapter. (If I'm wrong, then correct me).
But my whole problem is that in the adapter all interactions are used in BindView , or rather, I mean OnClickListener .
It turns out 1 fragment uses the adapter and on pressing there is one. 2 fragment does another, 3 - the third, etc.
The only option is to pass a variable to the adapter and perform a check. But, you see, it looks like something is not professional. If you remember, earlier in ListView was possible to render OnItemClickListener and all problems were solved. And what about RecyclerView ?
Here is what I understand from your answers.
public class PhotoAlbumsAdapter extends RecyclerView.Adapter<PhotoAlbumsAdapter.ViewHolder>{ private Context context; private OnItemClickListener onItemClickListener; private String str[] = {"test", "test", "test", "test", "test", "test", "test", "test", "test", "test"}; public PhotoAlbumsAdapter(Context context) { this.context = context; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.adapter_album_small, parent, false); return new ViewHolder(view); } @Override public void onBindViewHolder(ViewHolder holder, int position) { holder.txtTitle.setOnClickListener(onItemClickListener); } @Override public int getItemCount() { return str.length; } public void setOnItemClickListener(OnItemClickListener onItemClickListener){ this.onItemClickListener= onItemClickListener; } static class ViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.imgAlbum) ImageView imgAlbum; @BindView(R.id.txtTitle) TextView txtTitle; ViewHolder(View view) { super(view); ButterKnife.bind(this, view); } } public interface OnItemClickListener{ void onClick(); } } holder.txtTitle.setOnClickListener(onItemClickListener); IDEA marks in red. What to do?