Issue
Possible Duplicate:
Android dynamic String Resources
I have the following:
TextView text = (TextView)vi.findViewById(R.id.text);
TextView txtSub = (TextView)vi.findViewById(R.id.txtSub);
TextView txtA = (TextView)vi.findViewById(R.id.txtA);
TextView txtB = (TextView)vi.findViewById(R.id.txtB);
Is it possible to access these using a String instead (this just pseudocode)?
String resourceName = "text";
TextView text = (TextView)vi.findViewById(R.id. + resourceName);
Solution
Use Resources.getIdentifier():
int resource = getResources().getIdentifier("R.id."+resourceName, "string", getPackageName());
TextView text = (TextView)vi.findViewById(resource);
Answered By - znat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.