Skip to content

Instantly share code, notes, and snippets.

@gabrielemariotti
Created March 10, 2014 19:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielemariotti/9472154 to your computer and use it in GitHub Desktop.
Save gabrielemariotti/9472154 to your computer and use it in GitHub Desktop.
Cardslib: an example to expand cards clicking the whole card in a ListView.
public class ExpandWholeCardFragment extends BaseFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initCard();
}
/**
* This method builds a simple card
*/
private void initCard() {
//Init an array of Cards
ArrayList<Card> cards = new ArrayList<Card>();
for (int i = 0; i < 30; i++) {
CardInside card = new CardInside(this.getActivity());
//Create a CardHeader
CardHeader header = new CardHeader(getActivity(), R.layout.carddemo_extras_expandinside_inner_base_header);
//Set the header title
header.setTitle(getString(R.string.carddemo_extras_header_expand_area_inside));
//Add Header to card
card.addCardHeader(header);
CardExpandInside expand = new CardExpandInside(getActivity());
card.addCardExpand(expand);
cards.add(card);
}
CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(getActivity(), cards);
CardListView listView = (CardListView) getActivity().findViewById(R.id.carddemo_extra_list_mixinside);
if (listView != null) {
listView.setAdapter(mCardArrayAdapter);
}
}
public class CardInside extends Card {
public CardInside(Context context) {
super(context);
}
@Override
public void setupInnerViewElements(ViewGroup parent, View view) {
//Example on the card
ViewToClickToExpand viewToClickToExpand =
ViewToClickToExpand.builder()
.highlightView(false)
.setupView(getCardView());
setViewToClickToExpand(viewToClickToExpand);
}
}
class CardExpandInside extends CardExpand {
public CardExpandInside(Context context) {
super(context, R.layout.carddemo_extras_list_card_expandinside_expand_inner);
}
@Override
public void setupInnerViewElements(ViewGroup parent, View view) {
ImageView img = (ImageView) view.findViewById(R.id.carddemo_inside_image);
//.....
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment