2017-08-20 87 views
0

我使用的滑行庫加載圖像和我做的,是這樣的一種方法:我怎樣才能設置一個字符串變量R.drawable與滑行?

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

但它不工作,我想知道是否有使用字符串的方式用可繪製的名稱,以便我可以使用一個函數來動態設置圖像。

回答

0

您可以按名稱與此代碼獲取繪製資源的int值:

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

謝謝,這個工作。 –

相關問題