Thursday, August 25, 2011

Calling Android Resources Dynamically by passing String names

Suppose you have 3 types of resources (String, Drawable and Raw) for 50 kinds of animals like the following:

And suppose you want just 3 resources (String, Drawable and Raw) to be loaded for the ONE specific animal which the user will choose ONE at a time - that's gonna be like 50 if-else conditional statements with 3 resource definitions each = 150 lines of code.

With the following example, you can reduce it down to just about 36 lines of code to do exactly that.

1 comment:

  1. Dude, Excellent solution.. I was struggling with this problem for a long time.. U r great..