I really don't know why I can't use getLayoutPosition();
or getAdapterPosition();
methods inside my class.
class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private ImageView image;
private TextView title;
private TextView price;
public MyViewHolder(View itemView) {
super(itemView);
image = (ImageView)itemView.findViewById(R.id.horizontal_list_image);
title = (TextView)itemView.findViewById(R.id.horizontal_list_title);
price = (TextView)itemView.findViewById(R.id.horizontal_list_price);
image.setOnClickListener(this);
title.setOnClickListener(this);
price.setOnClickListener(this);
}
public ImageView getImage() {
return image;
}
public TextView getTitle() {
return title;
}
public TextView getPrice() {
return price;
}
@Override
public void onClick(View v) {
Toast.makeText(context, "CLICK", Toast.LENGTH_SHORT).show();
getLayoutPosition(); //no method like that
}
}
I can use however getPosition()
but is deprecated and above methods are advised. documentation