获取资源 id Imageview(ImageView 数组)

Get resource id Imageview (array of ImageViews)

如何在 android 中检索 imageView 数组的 resource_id?我知道如何为可绘制资源获取 i

int resId = context.getResources().getIdentifier("[imagename]" + indexNumber, "drawable", context.getPackageName());

但现在我想检索位于布局文件夹中的 imageView 的 ID (activity_main.xml)

原因是我有 10 个不同的图像视图,除了 indexnumer 之外名称相似。

我的完整代码

    ImageView[] imageView = new ImageView[10];
    AnimationDrawable[] frameAnimation = new AnimationDrawable[10];
    for (int i = 0; i < 10; i++) {

        int id = ???
        imageView[i] = (ImageView) findViewById(id);
        imageView[i].setBackgroundResource(R.drawable.gold_coin_animation);

        // Get the background, which has been compiled to an AnimationDrawable object.
        frameAnimation[i] = (AnimationDrawable) imageView[i].getBackground();

        frameAnimation[i].start();
    }

图片名称是

gold_coin_id1
gold_coin_id2
gold_coin_id3
...
gold_coin_id110

所以我想通过前缀 (gold_coin) 与索引号

连接来检索视图的资源 ID

这应该有效

int id = getResources().getIdentifier("gold_coin_id"+i, "id", getPackageName());
imageView[i] = (ImageView) findViewById(id);