ランダムなケースで複数のボタンを作成するfor関数を作成しようとしています。
変数を使用してこれらのボタンを作成する方法がわかりません。
これが私のコードの一部です:
位置文字列は、作成するボタンを決定するためのものです。showButton文字列は、使用しているボタンIDを判別するためのものです。
string showButton, position;
for(int i = 1; i<=12; i++)
{
showButton = "imagebutton" + i;
position = "position" + i;
Random random = new Random();
int randomNum = random.Next(1,4);
switch (randomNum)
{
case 1:
ImageButton position = FindViewById<ImageButton>(Resource.Id.showButton);
position1.SetImageResource(Resource.Drawable.buttonGreen);
btnPosition.Click += (o, e) =>
{
Toast.MakeText(this, "Você venceu", ToastLength.Short).Show();
};
break;
case 2:
SetContentView(Resource.Layout.Main);
ImageButton position = FindViewById<ImageButton>(Resource.Id.showButton);
position.SetImageResource(Resource.Drawable.buttonYellow);
position.Click += (o, e) =>
{
Toast.MakeText(this, "Você Venceu", ToastLength.Short).Show();
};
break;
case 3:
SetContentView(Resource.Layout.Main);
ImageButton position = FindViewById<ImageButton>(Resource.Id.showButton);
position.SetImageResource(Resource.Drawable.buttonRed);
position.Click += (o, e) =>
{
Toast.MakeText(this, "Você Perdeu", ToastLength.Short).Show();
};
break;
}