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.html#getIdentifier(java.lang.String,%20java.lang.String,%20java.lang.String)

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 android-developers@googlegroups.com
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