recyclerview No adapter attached; skipping layout

后端 未结 30 3695
走了就别回头了
走了就别回头了 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:17

    First initialize the adapter

    public void initializeComments(){
        comments = new ArrayList<>();
    
        comments_myRecyclerView = (RecyclerView) findViewById(R.id.comments_recycler);
        comments_mLayoutManager = new LinearLayoutManager(myContext);
        comments_myRecyclerView.setLayoutManager(comments_mLayoutManager);
    
        updateComments();
        getCommentsData();
    
    }
    
    public void updateComments(){
    
        comments_mAdapter = new CommentsAdapter(comments, myContext);
        comments_myRecyclerView.setAdapter(comments_mAdapter);
    }
    

    When ever there is a change in the dataset set, just call the updateComments method.

提交回复
热议问题