我正在尝试在Android Studio中制作一个RecyclerView,并且我正在努力从RecyclerView.Adapter<>()继承。
以下是包含问题的代码片段:
package Adapters
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.R
import android.os.Bundle
import models.Post
class PostAdapter(private val postList: List<Post>, private val content: String) : RecyclerView.Adapter<PostAdapter.PostViewHolder>() {Android Studio将"RecyclerView“设置为红色,我无法摆脱它。我尝试了stackoverflow上其他帖子中的解决方案,尝试遵循互联网上的教程,但没有任何关于androidx的内容,我也不能使用旧版本(android.support.v7.widget.RecyclerView),因为Android Studio不允许我使用。我在市电build.gradle中导入了RecyclerView:
implementation "androidx.recyclerview:recyclerview:1.1.0"并在最高实例的build.gradle中添加了google(),我希望我正确地解释了这个问题,您可以帮助我。
发布于 2020-01-13 04:57:51
我想你错过了回收器视图的导入
import androidx.recyclerview.widget.RecyclerView另外,如果您刚刚迁移到Android X,Android studio可能会出现错误,因此您希望使用File -> Invalidate Caches/Restart
发布于 2020-07-13 20:23:25
解决了!您是否记得在将回收器视图添加到主活动中后为其指定id?如果是,则检查以确保您提供的id与导致未解决错误的红色文本完全相同。例如
如果在main_activity.xml中,您有
`<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />`那么在MainActivity.kt中你应该有
`recyclerView.layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)`单词"recyclerView“在使用它的两个文件中应该完全相同
https://stackoverflow.com/questions/59707963
复制相似问题