user2999980
user2999980

Reputation: 31

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!

Upvotes: 0

Views: 335

Answers (2)

Abdul Rahman A Samad
Abdul Rahman A Samad

Reputation: 1152

I use this:

Context context = getActivity();

so for all the "this" inside the code sample, I replace it with "context" above. Hope this helps.

Upvotes: 0

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364858

Use:

Card card = new Card(getActivity());

in onActivityCreated(Bundle savedInstanceState)

Upvotes: 2

Related Questions