E / RecyclerView:未连接适配器;跳过科特林的布局

时间:2020-08-09 02:43:03

标签: kotlin android-recyclerview

**我想知道发生了什么错误,请告诉我该错误的解决方案:有人可以告诉我如何解决此问题: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")
            }


       

2 个答案:

答案 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"/
  1. 检查您正在使用的上下文。如果其为null,则适配器可能无法连接,并且可能发生上述错误
  2. app:layoutManager =“ androidx.recyclerview.widget.LinearLayoutManager”此行可以帮助您摆脱上述错误。