Skip to content Skip to sidebar Skip to footer

Generate Cards With Cardslib And Load Images With Picasso

I am using cardslib (https://github.com/gabrielemariotti/cardslib) to create a project with cards and use picasso (http://square.github.io/picasso/), in order to dynamically create

Solution 1:

I use CardsLib and picasso together for almost all my cards. What I recommend you is to make a CustomCard which extends card and receives a ParseObject as a parameter for the card.

It would make your code much simpler as well as you would add your cards to the list this way:

for(ParseObject p : List) {
    cards.add(new MyCustomCard(mContext, p));
}

Your custom card would look something like this:

publicclassMyCustomCardextendsCardimplementsCard.OnCardClickListener {

    privatestaticfinalStringLOG_TAG= MyCustomCard.class.getSimpleName();
    private ParseObject parseObject;

    publicMyCustomCard(Context context, ParseObject data) {
        super(context, R.layout.my_custom_layout);
        this.parseObject = data;
        this.setOnClickListener(this);
    }

    @OverridepublicvoidsetupInnerViewElements(ViewGroup parent, View view) {
        super.setupInnerViewElements(parent, view);

        ImageViewimageView= (ImageView)         view.findViewById(R.id.data_thumbnail);
        TextViewtitle= (TextView) view.findViewById(R.id.title);
        TextViewtext= (TextView) view.findViewById(R.id.text);

        if(parseObject != null) {
            Picasso.with(getContext()).load(parseObject.getString("picture")).fit().into(imageView);
            title.setText(parseObject.getString("title"));
            text.setText(parseObject.getString("text"));
        }
    }

    @OverridepublicvoidonClick(Card card, View view) {
       // in case your cards need to click on something. You don't need to // override onCLick if you don't wish to have click functionality on the cards

    }
}

You could even extend the MaterialLargeImageCard and use it's own XML instead of making your own.

I have some custom cards with Picasso examples in a few of my projects on github: check this project for more examples

Post a Comment for "Generate Cards With Cardslib And Load Images With Picasso"