Looking for an example of how to dynamically add controls from the activity.
Inside an activity, lets call it “Activity2.cs”, dynamically add a variable number of buttons to “MyView.axml”.
I’m looking for code like below (except code that actually works):
string[] textArray = new string[] { "button1", "button2", "button3", "button4" };
int counter= 3;
for (int i = 0; i < length; i++)
{
var mytest = new button(this);
mytest.Text = textArray[i];
mytest.id= textArray[i];
View(MyView.axml).add(mytest);
}
The result would be that four buttons are added at the bottom of the view. I can find examples for how to dynamically add controls in Android, but not when using Mono for Android (ie in Visual Studio).
Let’s say your layout file looks like this (Main.axml):
Then in your activity you can add Button objects to the layout like this: