0

I'm trying to use databinding in recycler view and i have problem. on data-variable i can't choose my real type (instead, i can choose type as default package. and then i cannot access to my variable on my adapter class. i got the error on adapter on line: binding.curMovie = movie. the error i get is: cannot access class movieItem Check your module classpath for missing or conflicting dependencies binding

MovieItem.kt file

import com.google.gson.annotations.SerializedName

data class MovieItem(

    @SerializedName("popularity") val popularity: Double,
    @SerializedName("id") val id: Int,
    @SerializedName("video") val video: Boolean,
    @SerializedName("vote_count") val vote_count: Int,
    @SerializedName("vote_average") val vote_average: Double,
    @SerializedName("title") val title: String?,
    @SerializedName("release_date") val release_date: String?,
    @SerializedName("original_language") val original_language: String?,
    @SerializedName("original_title") val original_title: String?,
    @SerializedName("genre_ids") val genre_ids: List<Int>,
    @SerializedName("backdrop_path") val backdrop_path: String?,
    @SerializedName("adult") val adult: Boolean,
    @SerializedName("overview") val overview: String?,
    @SerializedName("poster_path") val poster_path: String?
)

list_item.xml file

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>
        <variable
            name="curMovie"
            type="MovieItem" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <TextView
            android:id="@android:id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:minHeight="?android:attr/listPreferredItemHeightSmall"
            android:paddingStart="?android:attr/listPreferredItemPaddingStart"
            android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
            android:text="@{curMovie.title}"
            android:textAppearance="?android:attr/textAppearanceListItemSmall"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:text="my movie" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>

MovieAdapter.kt file

class MovieAdapter() : RecyclerView.Adapter<MovieAdapter.MovieViewHolder>() {

    var moviesList: List<MovieItem> = ArrayList()



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MovieViewHolder {
        val inflater = LayoutInflater.from(parent.context)

        val binding = ListItemBinding.inflate(inflater)


        return MovieViewHolder(binding)

    }

    override fun getItemCount(): Int {
        return moviesList.size
    }

    override fun onBindViewHolder(holder: MovieViewHolder, position: Int) {
        val movie = moviesList.get(position)

        holder.setMovieData(movie)
    }

    class MovieViewHolder(val binding: ListItemBinding) : RecyclerView.ViewHolder(binding.root) {
        fun setMovieData(movie: MovieItem) {
            binding.curMovie = movie
        }
    }

    fun setMovieList(moviesList : List<MovieItem>){
        this.moviesList = moviesList
        notifyDataSetChanged()
    }

}

my package files

Bruse
  • 303
  • 1
  • 6
  • 20

1 Answers1

0

Most likely, the pakage name begins with a capital letter https://stackoverflow.com/a/54752522/11738109 or in list_item.xml use the full class path instead of a brief MovieItem

Evgeny
  • 431
  • 3
  • 10
  • no capital letter in my package. i can access to my Repository on my type, but not to MovieItem. i've uploaded package screenshot – Bruse Feb 12 '20 at 15:06
  • You already tried to do like this type="com.example.myapplication.model.MovieItem"? And check for "package com.example.myapplication.model" above import in MovieItem file. – Evgeny Feb 12 '20 at 15:24
  • I've tried this already, i get cannot resolved symbol for MovieItem. already tried clean/invalidate etc. – Bruse Feb 12 '20 at 15:26