0

Bit of a newbie here, I am trying to build a RecyclerView with some CardViews with images. I want to launch a new activity with a shared element transition of the image from the card.

My view holder:

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    String animal = mData.get(position);
    holder.myTextView.setText(animal);
    holder.myDescrition.setText("Test description");
    holder.myImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, getItem(position));
            Intent i = new Intent(view.getContext(), details.class);
            view.getContext().startActivity(i, options.toBundle());

        }
    });
}

But i keep getting the error Error:(64, 88) error: incompatible types: <anonymous OnClickListener> cannot be converted to Activity

notnavindu
  • 372
  • 1
  • 3
  • 14

1 Answers1

0

From your error it says that you cannot have the anonymous OnClickListener type convert to an Activity. So make sure the activity that you are using looks something like this:

public class MainActivity extends AppCompatActivity implements  View.OnClickListener {
       //....
}

Make sure that your activity implements View.OnClickListener.

beastlyCoder
  • 2,301
  • 3
  • 21
  • 46