如何使用 glide 在 R.drawable 上设置字符串变量?

How can I set a String variable on R.drawable with glide?

我正在使用 glide Library 加载图像,我做了一个这样的方法:

void alterarInformacoes(ImageView slotImagem, String image) {
        Glide.with(this)
                .load(R.drawable.image)
                .into(slotImagem);
    }

但它不起作用,我想知道是否有办法使用带有可绘制对象名称的字符串,以便我可以使用函数来动态设置图像。

您可以使用以下代码通过名称获取可绘制资源的 int 值:

int drawableResourceId = this.getResources().getIdentifier("nameOfDrawable", "drawable", this.getPackageName());