0

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!

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
user2999980
  • 31
  • 2
  • 8
  • I suggest you to use the CardView provided by Google in the new support library provided with the preview of Android L. In this way you have a "real" library and support even in the future. – greywolf82 Aug 24 '14 at 14:45
  • I didn't even know that existed. So much for me doing my homework. I'll have to check it out. Thanks! – user2999980 Aug 24 '14 at 15:54
  • You can't compare them. IT depends on what you need. CardView provided by Google is just a FrameLayout. Cardslib provided some built-in features over it. If you only need a layout, use the google cardView. In anycase, cardslib will work with the new Google CardView. – Gabriele Mariotti Aug 27 '14 at 07:54

2 Answers2

2

Use:

Card card = new Card(getActivity());

in onActivityCreated(Bundle savedInstanceState)

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

I use this:

Context context = getActivity();

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

Abdul Rahman A Samad
  • 1,062
  • 1
  • 15
  • 21