<分区>
我想创建一个国家和国旗选择器。我想设置一面旗帜的图像,但我想根据其名称选择该图像。基本上,我正在尝试为 Android 创建一个标志和 ISD 代码选择器,以便我可以使用它在电话号码的用户之前添加一个 ISD 代码。
ImageView img1 = (ImageView)findViewById(R.id.imgFlag);
img1.setBackgroundResource(R.drawable.India_91);
适配器中的类似内容。
// India_91 is an image India_91.png,
// suppose if I have USA_1.png as image then i should be able to use
// string "USA_1" to get the related resource and set it as
// BackgroundResource.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
long resId = getResourceIdUsingResourceString(arrayOfStrings[position]);
// I should get the Id of the image
// resource named as"USA_91"
}
// This is a utility function outside adapter class
long getResourceIdUsingResourceString(string resourceName) {
// Here I want to add a code which can check for
// resource name and then get id of it
// which can then be used by callee function/block
// to fetch the correct resource and display it
}