Display a RecyclerView in Fragment

后端 未结 4 2142
离开以前
离开以前 2020-12-04 06:25

I\'m trying out the new RecyclerView in Android Lollipop and I\'m stuck.

I\'m trying to receive a list, with an icon and a TextView to the

4条回答
  •  伪装坚强ぢ
    2020-12-04 07:02

    I faced same problem. And got the solution when I use this code to call context. I use Grid Layout. If you use another one you can change.

       recyclerView.setLayoutManager(new GridLayoutManager(getActivity(),1));
    

    if you have adapter to set. So you can follow this. Just call the getContext

      adapter = new Adapter(getContext(), myModelList);
    

    If you have Toast to show, use same thing above

       Toast.makeText(getContext(), "Error in "+e, Toast.LENGTH_SHORT).show();
    

    Hope this will work.

    HappyCoding

提交回复
热议问题