kotlin - E/RecyclerView:没有附加适配器;在 kotlin 中跳过布局
问题描述
** 我想知道我犯了什么错误 跳过布局,我还不能解决请告诉我如何解决这个错误.................................. ..................................................... ..................................................... ......**
搜索.xml
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/app_bar_layout_search"
android:visibility="gone">
</androidx.recyclerview.widget.RecyclerView>
搜索.kt
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view=inflater.inflate(R.layout.fragment_search, container, false)
recyclerView=view.findViewById(R.id.recycler_view_search)
recyclerView?.setHasFixedSize(true)
recyclerView?.layoutManager=LinearLayoutManager(context)
mUser=ArrayList()
userAdapter=context?.let{ UserAdapter(it,mUser as
ArrayList<User>,true) }
recyclerView?.adapter=userAdapter
view.search_edit_text.addTextChangedListener(object: TextWatcher{
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
TODO("Not yet implemented")
}
解决方案
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_hashtags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
tools:listitem="@layout/item_trending"/
- 检查您正在使用的上下文。如果它为空,则适配器可能无法连接,并且可能会发生上述错误
- app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" 这行可以帮你摆脱上面的错误。
推荐阅读
- glibc - 是否可以从 C 代码运行 __libc_start_main ?
- java - 如何从 LinkedHashMap 中检索最后 N 个元素
- python - 如果类实例作为初始化参数传递,则不要中断
- android - 颤振开关自行关闭
- excel - 资源耗尽时分配下一个可用人员
- python - 如何为 DateTime 比较定义 Flask-SQLAlchemy(MySQL) 混合属性或聚合属性
- mongodb - 获取匹配值的索引
- javascript - Chain To Then 函数同时在 ES6 中封装一个
- java - 从文本文件中读取一行而不是整个文件(使用缓冲阅读器)
- r - R 如何使用贝叶斯回归模型进行预测?