**我想知道发生了什么错误,请告诉我该错误的解决方案:有人可以告诉我如何解决此问题:E / RecyclerView:未连接适配器;跳过布局,我仍然无法解决,请告诉我如何解决此错误................................. ................................................... ................................................... ...... **
search.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>
search.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")
}
答案 0 :(得分:0)
尝试将“ RecyclerView.VERTICAL,false”添加到LinearLayoutManager初始化中,如下所示 LinearLayoutManager(上下文,RecyclerView.VERTICAL,false) 还要确保适配器已正确初始化(在useAdapter初始化后尝试添加日志)
答案 1 :(得分:0)
<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"/