Sascha K.
Sascha K.

Reputation: 653

getAdapterPosition() is not a method

in my new Android Project, i have the following Problem, when i want to get the current position in the RecyclerView:

Cannot resolve method 'getAdapterPosition()'

In my other Android Studio Projects, it's work's fine.

    public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    protected TextView itemName;
    protected ImageView itemIcon;

    public MyViewHolder(View v, UserClickListener listener) {
        super(v);
        // a- A
        mListener = listener;

        itemName = (TextView) v.findViewById(R.id.rowText);
        itemIcon = (ImageView) v.findViewById(R.id.rowIcon);

        v.setOnClickListener(this);
    }

    public void onClick(View v) { mListener.onClick(v, getAdapterPosition()); }
}

in the build.gradle i have this:

compile 'com.android.support:recyclerview-v7:21.0.3'

Upvotes: 4

Views: 3285

Answers (1)

Blackbelt
Blackbelt

Reputation: 157457

getAdapterPosition() is part of v22, of the support library, so the only way to use it, is to upgrade it. Here you can find the changelog

Upvotes: 6

Related Questions