Using CardView and RecyclerView in my layout files throws an exception

前端 未结 4 1283
[愿得一人]
[愿得一人] 2021-02-13 20:06

So I\'ve been taking a shot at the Material Design of Android Preview L. I imported both the CardView and the RecyclerView libraries.

I use the

4条回答
  •  自闭症患者
    2021-02-13 21:03

    If some one is facing the same issue for Recycler view inside fragment use this code

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View rootView = inflater.inflate(R.layout.fragment_timeline, container, false);
    
            mRecyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);
    
            // use this setting to improve performance if you know that changes
            // in content do not change the layout size of the RecyclerView
    
            mRecyclerView.setHasFixedSize(true);
            // use a linear layout manager
            mLayoutManager = new LinearLayoutManager(getActivity());
            mRecyclerView.setLayoutManager(mLayoutManager);
    
    
            String[] abc = {"hi","how are you","this is recycler"};
            // specify an adapter (see also next example)
            mAdapter = new RecyclerViewAdapter(abc);
            mRecyclerView.setAdapter(mAdapter);
            return rootView;
        }
    

提交回复
热议问题