Created
March 10, 2014 19:13
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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