No adapter attached; skipping layout [duplicate]

吃可爱长大的小学妹 提交于 2019-11-26 07:48:06

问题


This question already has an answer here:

  • recyclerview No adapter attached; skipping layout 30 answers

logcat error : No adapter attached; skipping layout

I changed the context argument with getActivity(), but the app is still not running.

public class FragmentActivity extends Fragment {  
    private RecyclerView mRecyclerView;
    private CountryAdapter mAdapter;
    private LinearLayoutManager layoutManager;
    public FragmentActivity(){}
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_main, container, false);
        mRecyclerView = (RecyclerView) rootView.findViewById(R.id.list);
        layoutManager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter = new CountryAdapter(CountryManager.getInstance().getCountries(), R.layout.card_layout, getActivity());
        return rootView;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }
}

回答1:


You didn't attach the adapter because you create it after you try to attach it:

mRecyclerView.setAdapter(mAdapter); // Here, mAdapter is null
mAdapter = new CountryAdapter(CountryManager.getInstance().getCountries(), R.layout.card_layout, getActivity());



回答2:


In my case this problem occurs because there was a view on my layout which moved my list container and it was displayed too small



来源:https://stackoverflow.com/questions/28510578/no-adapter-attached-skipping-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!