I want to do
String childImg = "childIcon";
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.????, 0, 0, 0);
it's expecting an int but i have a string. how do i work around this?
I want to do
String childImg = "childIcon";
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.????, 0, 0, 0);
it's expecting an int but i have a string. how do i work around this?
I use this to get drawable id
getResources().getIdentifier(childImg, "drawable", getPackageName())
use getIdentifier()
int id = getResources().getIdentifier("name_of_resource", "id", getPackageName());
Do it like this:
String childImg = "childIcon";
int id = getResources().getIdentifier(childImg, "drawable", getPackageName())
textView.setCompoundDrawablesWithIntrinsicBounds(id, 0, 0, 0);
textView.setCompoundDrawablesWithIntrinsicBounds(Resources.getIdentifier(childImg), 0, 0, 0);