Don't use Resources.getIdentifier() unless you really for some reason
only have the string name of the resource.  Which should be close to
never, because the resource compiler generates all of those nice
symbols in the R class for all of the resource identifiers, giving you
compile time checking and much much faster access.

On Apr 9, 8:49 pm, Adriano Crestani <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Try to use the Resources.getIdentifier(String, String, String). Look
> at its documentation for more 
> details:http://code.google.com/android/reference/android/content/Resources.ht...)
>
> Regards,
> Adriano Crestani
>
> On Apr 6, 4:48 pm, xingye <[EMAIL PROTECTED]> wrote:
>
> > use Map structure
>
> > On 4月7日, 上午2时15分, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > But if you already know ahead of time that the resource name is
> > > "my.package.R.drawable.resname", then you already know what imageID
> > > is, so you wouldn't need that. Or am I misunderstanding what you are
> > > trying to do?
>
> > > On Apr 6, 6:36 am, Max Binshtok <[EMAIL PROTECTED]> wrote:
>
> > > > Is there a mechanism to dynamically obtain a resource?
>
> > > > I mean, let's say I want to show some image depending on context out
> > > > of 5 images I have in drawable dir.
> > > > So I would expect something like
>
> > > > getResourceByName(String s) : int
>
> > > > which would take a string that points to the resource and will get me
> > > > the int of that resource.
>
> > > > for example, I could do then:
>
> > > >                 ImageView iv = (ImageView) findViewById(R.id.sign_icon);
>
> > > >                 int imageID 
> > > > getResourceByName("my.package.R.drawable.resname");
> > > >                 iv.setImageResource(imageID);
>
> > > > One way to overcome it would be to hold a hashmap where "resname"
> > > > point to appropriate resource and then use the resname to get it, but
> > > > I think this should be native. Or it is but I can't figure it out.
>
> > > > Thanks for the help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to