Is it possible to create a card view from the activity

82 Views Asked by At

I am creating an app in which you learn Spanish, in order to learn the words I want to create cards that one side will show the word in Spanish and the other will show the word in English I won’t be able to know the amount of words, therefore I want to create the card views from the activity and not from the xml Is it possible? I’m using xamarin android in visual studio

I tried to change the text on the cardView but I wasn’t able to do so, also I think the better option is to create new cards for each word

1

There are 1 best solutions below

6
Liyun Zhang - MSFT On

Yes, you can create create a card view from the activity. You can add the following code into the activity to create a new CardView.

var cardview = new CardView(this);
var layoutparams = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);
cardview.LayoutParameters = layoutparams;
// and you can set the card view's other properties

//if you want to add the card view into the linearlayout you can use
linearlayout.AddView(cardview,0); // the 0 is the index of the linearlayout

For more information, you can refer to the case about how to create programmatically CardView