I have a custom object :
Student.class
public class Student {
private String name;
private String age;
public String getName() {
return name;
You need to set on onClickListener()
on the view of the ViewHolder
i.e. itemView in your case. It will call the onClick()
method as soon as you click the complete view i.e. root view (itemView in your case)
you can also set onClickListener()
on the children of the root i.e. name and age.
inside ViewHolder(View itemView) constructor:
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext,"clicked="+ getPosition(),Toast.LENGTH_SHORT).show();
}
});
Similarly you can call onLongClickListner()
also.
And name.setOnClickLisner()
on child view too.