C# Xamarin-如何动态更改图像源?
我遵循这个教程,工作得很好。 但就我而言,我有200张照片。用户将文字写在编辑文本中,点击按钮后,显示相应的图片。 如何更改下面代码中的图片源代码:C# Xamarin-如何动态更改图像源?,c#,android,image,xamarin,main-activity,C#,Android,Image,Xamarin,Main Activity,我遵循这个教程,工作得很好。 但就我而言,我有200张照片。用户将文字写在编辑文本中,点击按钮后,显示相应的图片。 如何更改下面代码中的图片源代码: EditText edit = FindViewById<EditText>(Resource.Id.edtName); button.Click += delegate { img.SetImageResource(Resource.Drawable.sample2);
EditText edit = FindViewById<EditText>(Resource.Id.edtName);
button.Click += delegate
{
img.SetImageResource(Resource.Drawable.sample2);
};
EditText edit=findviewbyd(Resource.Id.edtName);
按钮。单击+=委派
{
img.SetImageResource(Resource.Drawable.sample2);
};
其中“sample2”更改为edit.Text。(为用户编写文本…使用方法更改可绘制的
public void changePhoto()
{
int MyPhoto;
if (edit.Text != string.Empty)
{
try
{
MyPhoto = (int)typeof(Resource.Drawable).GetField(edit.Text).GetValue(null);
}
catch
{
MyPhoto = Resource.Drawable.ErrorPhoto;
}
img.SetImageResource(MyPhoto);
}
}
button.Click += delegate
{
changePhoto();
};