I would like to set ImageView resource from string dynamically, but I could not do that with following method.
I am using Xamarin/Android to set ImageView resource dynamically as below;
ImageView homeItemImage = convertView.FindViewById<ImageView>(Resource.Id.homeItemImage);
int imageId = PlatformProvider.GetImageId(Context, contentTitle.IconImageUrl);
homeItemImage.SetImageResource(imageId);
GetImageId function:
public static int GetImageId(Context context, string imageName)
{
// int identifier = context.Resources.GetIdentifier(imageName, "drawable", context.PackageName);
int identifier = context.Resources.GetIdentifier(context.PackageName + ":drawable/" + imageName, null, context.PackageName);
return identifier;
}
I am passing imageName both wasy as "Account.png" or "Account" both returns int as 0.
Here is my image folder:
And I set them up as AndroidResource (here is shows About.png but Account.png is same way):
They show in intellisense:
How can I set image source from string?