Skip to content

Instantly share code, notes, and snippets.

@gabrielemariotti
Created September 2, 2014 17:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielemariotti/4200d059f100cdf832f6 to your computer and use it in GitHub Desktop.
Save gabrielemariotti/4200d059f100cdf832f6 to your computer and use it in GitHub Desktop.
A simple gist to build a MaterialCard with cardslib v2.
//Create a Card, set the title over the image and set the thumbnail
MaterialLargeImageCard card = new MaterialLargeImageCard(getActivity());
card.setTextOverImage("Italian Beaches");
card.setDrawableCardThumbnail(R.drawable.sea);
//Set the title and subtitle in the card
card.setTitle("This is my favorite local beach");
card.setSubTitle("A wonderful place");
// Set supplemental actions
TextSupplementalAction t1 = new TextSupplementalAction(getActivity(), R.id.text1);
t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getActivity()," Click on Text SHARE ",Toast.LENGTH_SHORT).show();
}
});
card.addSupplementalAction(t1);
TextSupplementalAction t2 = new TextSupplementalAction(getActivity(), R.id.text2);
t2.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getActivity()," Click on Text LEARN ",Toast.LENGTH_SHORT).show();
}
});
card.addSupplementalAction(t2);
//Set the layout for supplemental actions
card.setLayout_supplemental_actions_id(R.layout.carddemo_native_material_supplemental_actions_large);
//Very important call: build the card
card.build();
//Set card in the CardViewNative
CardViewNative cardView = (CardViewNative) getActivity().findViewById(R.id.carddemo_largeimage_text);
cardView.setCard(card);
@sumitsahoo
Copy link

Thanks for this great library. I want this Material Card to place under RecyclerView. To do that somehow I need to pass the layout information i.e. R.layout.native_material_largeimage_text_card

But if I pass it in constructor the layout isn't coming. Also in line 4, the drawable method changed to card.setDrawableIdCardThumbnail(R.drawable.sea);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment