How to make base material card of Cardslib library expand when I click on a text supplemental action

438 views Asked by At

I have implemented new Material Card design from CardsLib library from Github and using multiple cards inside Recycler view. The card layout I have implemented is:

enter image description here

Now I want to make the Card Expand when I click on 'LEARN MORE' in the card and inflate my custom layout in it. How can I implement this? Here is a snippet of code in my MainActivty.java file:

public class MainActivity extends ActionBarActivity {


final int TOTAL_CARDS = 3;
//private CardArrayAdapter
private CardArrayRecyclerViewAdapter mCardArrayAdapter;
private CardRecyclerView mRecyclerView;
String productname;
String price;
int pimage[]={R.drawable.ghewar,R.drawable.icehalwa,R.drawable.khakra};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ArrayList<Card> cards = new ArrayList<>();

    mCardArrayAdapter = new CardArrayRecyclerViewAdapter(this, cards);

    //Staggered grid view
    CardRecyclerView mRecyclerView = (CardRecyclerView) findViewById(R.id.card_recyclerview);
    mRecyclerView.setHasFixedSize(false);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    //Set the empty view
    if (mRecyclerView != null) {
        mRecyclerView.setAdapter(mCardArrayAdapter);
    }

    //Load cards
    new LoaderAsyncTask().execute();
}

private ArrayList<Card> initCard() {

    ArrayList<Card> cards = new ArrayList<Card>();
    for (int i = 0; i < TOTAL_CARDS; i++) {

        ArrayList<BaseSupplementalAction> actions = new ArrayList<BaseSupplementalAction>();
        // Set supplemental actions
        TextSupplementalAction t1 = new TextSupplementalAction(this, R.id.action1);
        t1.setOnActionClickListener(new BaseSupplementalAction.OnActionClickListener() {
            @Override
            public void onClick(Card card, View view) {
                Toast.makeText(MainActivity.this," Click on Text SHARE "+card.getTitle(),Toast.LENGTH_SHORT).show();

            }
        });
        switch(i){
            case 0: productname="Paneer Ghewar";
                    price="Rs 200";
                break;
            case 1: productname="Bombay Ice Halwa";
                    price="Rs 400";
                break;
            case 2: productname="Gujrati Khakra";
                    price="Rs 150";
                break;

        }
        //Create a Card, set the title over the image and set the thumbnail
        MaterialLargeImageCard card =
                MaterialLargeImageCard.with(this)
                        .setTextOverImage(productname)
                        .setTitle("This is my favorite delicacy!!")
                        .setSubTitle(price)
                        .useDrawableId(pimage[i])
                        .setupSupplementalActions(R.layout.carddemo_native_material_supplemental_actions_large_icon, actions)
                        .build();

        actions.add(t1);

        card.build();

        cards.add(card);

    }

        return cards;
}

If you need any more information do let me know. Thanks in advance!

0

There are 0 answers