i am currently facing a problem, is it possible to use the function "findViewById()" like this?
String[] names{ "a", "b"};
findViewById(R.drawable.names[0]);
EDIT: Just so you know, you can only call findViewById on R.id types. Thus, your code is bound to fail since you're calling it on R.drawable types.
Try getIdentifier(). Documentation
int resourceId = getResources().getIdentifier(names[0], "drawable", getPackageName());
findViewById(resourceId);
Note: The Android Documentation says:
use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.
In this case, it'll probably be better if you defined an array of int, and those contained the ids of the drawable resources.
No you cannot do that, but instead there is a work around for that. Try something like this:-
String[] names{ "a", "b"};
int drawableId = this.getResources().getIdentifier(names[0], "drawable", this.getPackageName());
findViewById(drawableId);
Where this is an Activity, written just to clarify.
In case you want a String in strings.xml or an identifier of a UI element, substitute the "drawable"
int resourceId = this.getResources().getIdentifier("nameOfResource", "id", this.getPackageName());
I must warn you, this way of obtaining identifiers is really slow, use only where needed.
findViewByIdandR.drawable? seems legit..