简体   繁体   English

未解决的参考:LinearLayoutManager/RecyclerView

[英]Unresolved reference: LinearLayoutManager/RecyclerView

I started building a movie database app using Kotlin based on a tutorial I found online (see this link for details. While building the movie fragment file, I noticed an "unresolved reference: LinearLayoutManager" and an "unresolved reference: RecyclerView" error. I have included the code below to and everything matches up like the tutorial except for those errors:我开始根据我在网上找到的教程使用 Kotlin 构建电影数据库应用程序(有关详细信息,请参阅此链接。在构建电影片段文件时,我注意到“未解析的引用:LinearLayoutManager”和“未解析的引用:RecyclerView”错误。我已经包含了下面的代码,除了那些错误之外,一切都像教程一样匹配:

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.dburgnerjr.movietvshowdatabase.R
import com.dburgnerjr.movietvshowdatabase.commons.inflate
import kotlinx.android.synthetic.main.movie_fragment.*

class MovieFragment : Fragment() {

    private val movieList by lazy {
        movie_list
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return container?.inflate(R.layout.movie_fragment)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        movieList.setHasFixedSize(true)
        movieList.layoutManager = LinearLayoutManager(context)
    }
}

Anything I overlooked?我忽略了什么?

Considering Jetpack, you can use AndroidX as:考虑到 Jetpack,您可以将AndroidX用作:

implementation 'androidx.recyclerview:recyclerview:1.0.0'

Instead of:而不是:

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

And in the layout.xml , you need something like:layout.xml ,您需要如下内容:

    <androidx.recyclerview.widget.RecyclerView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"/>

I figured it out.我想通了。 I saw this post and noticed that I missed a我看到这个帖子,发现我错过了一个

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

reference in my build.gradle file.在我的 build.gradle 文件中引用。 Problem solved.问题解决了。

if you use androidx, please changed your gradle with the below.如果您使用 androidx,请使用以下更改您的 gradle。

from :从 :

implementation 'com.android.support:recyclerview-v7:28.0.0'

to :到:

implementation 'androidx.recyclerview:recyclerview:1.0.0'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM