Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getPosition Deprecated What should I use instead?

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());
        }


    }
like image 999
Eli Avatar asked Jan 24 '16 01:01

Eli


People also ask

What is the purpose of ViewHolder?

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.

What is the use of onBindViewHolder in Android?

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.


1 Answers

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()

like image 104
TejjD Avatar answered Sep 25 '22 02:09

TejjD