recyclerview No adapter attached; skipping layout

后端 未结 30 3059
走了就别回头了
走了就别回头了 2020-11-21 04:51

Just implemented RecyclerView in my code, replacing ListView.

Everything works fine. The data is displayed.

But error messages are

30条回答
  •  伪装坚强ぢ
    2020-11-21 05:23

    I have solved this error. You just need to add layout manager and add the empty adapter.

    Like this code:

    myRecyclerView.setLayoutManager(...//your layout manager);
            myRecyclerView.setAdapter(new RecyclerView.Adapter() {
                @Override
                public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                    return null;
                }
    
                @Override
                public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    
                }
    
                @Override
                public int getItemCount() {
                    return 0;
                }
            });
    //other code's 
    // and for change you can use if(mrecyclerview.getadapter != speacialadapter){
    //replice your adapter
    //}
    

提交回复
热议问题