String childImg = "childIcon";
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.????, 0, 0, 0);
它期待一個整數,但我有一個字符串。我如何解決這個問題?
String childImg = "childIcon";
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.????, 0, 0, 0);
它期待一個整數,但我有一個字符串。我如何解決這個問題?
我用它來獲取繪製ID [機器人,讓資源ID的
getResources().getIdentifier(childImg, "drawable", getPackageName())
textView.setCompoundDrawablesWithIntrinsicBounds(Resources.getIdentifier(childImg), 0, 0, 0);
由於某種原因不起作用。圖像只是不出來 – code511788465541441
使用getIdentifier()
int id = getResources().getIdentifier("name_of_resource", "id", getPackageName());
由於某種原因不起作用。該圖像只是不出現 – code511788465541441
posible解決方案http://stackoverflow.com/questions/4427608/android-getting-resource-id-from-string – seba123neo
做這樣的:
String childImg = "childIcon";
int id = getResources().getIdentifier(childImg, "drawable", getPackageName())
textView.setCompoundDrawablesWithIntrinsicBounds(id, 0, 0, 0);
可能重複從字符串?](http://stackoverflow.com/ques tions/4427608/android-getting-resource-id-from-string) – kabuko