recyclerview No adapter attached; skipping layout

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

    // It happens when you are not setting the adapter during the creation phase: call notifyDataSetChanged() when api response is getting Its Working

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity);
    
    
            magazineAdapter = new MagazineAdapter(getContext(), null, this );
            newClipRecyclerView.setAdapter(magazineAdapter);
            magazineAdapter.notifyDataSetChanged();
    
           APICall();
    }
    
    public void APICall() {
        if(Response.isSuccessfull()){
        mRecyclerView.setAdapter(mAdapter);
       }
    }
    Just move setting the adapter into onCreate with an empty data and when you have the data call:
    
    mAdapter.notifyDataSetChanged();
    

提交回复
热议问题