Search code examples
androidkotlinandroid-recyclerviewandroid-transitionsshared-element-transition

makeSceneTransitionAnimation in recyclerview Android


Edit in base of your answer: How I could i implement an interfercae to have the click listener in mmy activity

class ViewHolder(view: View,contex: Context) : RecyclerView.ViewHolder(view){
val chapterName = view.textrowlinear
val c=contex
var imageView=view.image_view
var motivo=view.motivomore
var cardView=view.card_viewl

Because i would like to implement the second and the best method u suggest
Thank You


Solution

  • The first parameter expected in ActivityOptionsCompat.makeSceneTransitionAnimation is Activity, here you are trying to pass a Context, which is a super class of Activity, so the compiler cannot identify if the context you passed is an activity or any other Context, the simplest solution would be to typecast the Context to an activity by using as keyword

      val intent = Intent(holder.c, Dialog::class.java)
    //intent.putExtra("code", code)
    val options = ActivityOptionsCompat.makeSceneTransitionAnimation(
        holder.c as Activity, holder.imageView, ViewCompat.getTransitionName(holder.imageView)!!)
    holder.c.startActivity(intent, options.toBundle())
    

    Or most correct implementation would be to use an interface to get back the event from Recyclerview adapter to activity and call these methods inside activity