我有以下问题:
错误CS0029无法隐式转换类型'Android.Widget.ImageView [*,*,*]'到'Android.Widget.ImageView []'
ImageView[] MyImagen = new ImageView [
Resource.Drawable.uno,
Resource.Drawable.dos,
Resource.Drawable.tres
];
答案 0 :(得分:0)
试试这个:
ImageView[] MyImagen = new ImageView[] {
Resource.Drawable.uno,
Resource.Drawable.dos,
Resource.Drawable.tres
};
以前您将变量定义为三维数组ImageView[,,]
,不能分配给ImageView[]
。
答案 1 :(得分:-1)
解决方法如下
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
int numero, numero2;
ImageView imagen1 = FindViewById<ImageView>(Resource.Id.img_Dice1);
ImageView imagen2 = FindViewById<ImageView>(Resource.Id.img_Dice2);
Button botonP = FindViewById<Button>(Resource.Id.btnRoll);
Random ran = new Random();
int[] myImage = {
Resource.Drawable.uno,
Resource.Drawable.dos,
Resource.Drawable.tres,
Resource.Drawable.cuatro,
Resource.Drawable.cinco,
Resource.Drawable.seis
};
botonP.Click += (sender, e) =>
{
numero = ran.Next(0, 6);
numero2 = ran.Next(0, 6);
Console.WriteLine(numero + " " + numero2);
imagen1.SetImageResource(myImage[numero]);
imagen2.SetImageResource(myImage[numero2]);
};
}