Search code examples
androidandroid-fragmentsfragmentnavigation-drawercardslib

CardsLib and Fragments


I have been at this for quite a few days now and I cannot for the life of me figure this out so that's why I came here!

Right now I am trying to get CardsLib (GitHub Link Here) to work in a fragment. I am currently using a Navigation Drawer setup and every time I think i get it working as soon as it opens it crashes.

The reason it crashes is because when CardsLib goes to get the context (getActivity().getApplicationContext() it returns null and it throws and error on this piece of code cardView.setCard(card);

Now previously card is initialized as Card card = new Card(getContext()); which makes sense that the context is null.

If anyone could give me an example of CardsLib in a fragment that would be much help.

Thanks!


Solution

  • Use:

    Card card = new Card(getActivity());
    

    in onActivityCreated(Bundle savedInstanceState)