Android List of CardWithList

60 views Asked by At

I'm implementing Gabriele Mariotte's cardslib - CardWithList. Is there a way to dynamically create the cards and put them in a list?

I've tried looping through an arraylist in my initcard() method, but this seems to only create one card and overwrite the data that's displayed so only the last set of data is on the card (oddly enough with all of the headers in list).

The sample code basically creates all of the cards manually. I figured a for loop could do this by simply calling new WhateverCard, card.init and setting the view..this however doesn't seem to work. Sample below:

private void initCard() {

    //Create a Card
     card= new GoogleNowNativeWeatherCard(getActivity());
     card.init();

    //Set card in the cardView
    CardViewNative cardView = (CardViewNative) getActivity().findViewById(R.id.carddemo_weathercard);
    cardView.setCard(card);


    //Card
    card2 = new GoogleNowStockCardwithList(getActivity());
    card2.init();

    //Set card in the cardView
    CardViewNative cardView2 = (CardViewNative) getActivity().findViewById(R.id.carddemo_stockcard);
    cardView2.setCard(card2);

}
1

There are 1 answers

0
user3781123 On

Figured it out. In the demo code, the card's view is included in the XML layout. In my app, I needed to add the view to the layout in Java and then add the card to the view.