I am creating an onTouchListener
for a RecyclerView
item and getPosition()
is deprecated in the code below, what can I use as a substitute?
@Override
public void onClick(View v) {
context.startActivity(new Intent(context,NavigateTo.class));
if(clicklistener!=null)
{
clicklistener.itemClickd(v,getPosition());
}
}
A ViewHolder describes an item view and metadata about its place within the RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive findViewById results.
bindViewHolder. This method internally calls onBindViewHolder to update the ViewHolder contents with the item at the given position and also sets up some private fields to be used by RecyclerView.
Try getLayoutPosition()
This method is deprecated.
This method is deprecated because its meaning is ambiguous due to the async handling of adapter updates. Please use getLayoutPosition() or getAdapterPosition() depending on your use case.
See Also
getLayoutPosition()
getAdapterPosition()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With