2012-04-16 24 views

回答

27

使用此獲得資源ID:

int picId = getResources().getIdentifier(picName, "drawable", getApplicationContext().getPackageName()); 
+0

沒有任何方法像* getApplicationPackageName()*,而沒有看到答案如何可以upvote,啊。 – 2012-04-16 08:51:13

+0

對不起我的錯我已更新答案 – Nishant 2012-04-16 08:55:02

2
View view = findViewById(R.drawable.image1); 
int id = view.getId(); 
+0

這將返回'R.drawable.image1' ...您使用了一個您已經擁有的身份證,然後找到它,然後將其取回 – 2016-06-02 18:05:04

+0

這不會回答使用身份驗證的問題一個字符串,因爲你在findViewById中對它進行硬編碼 – Alejandro 2016-07-31 18:55:54

3

如果你想獲得integer然後簡單地刪除引號。

int id = R.drawable.image1; // instead of "R.drawable.image1" 

這會給你的號碼。

相關問題