Sunday, September 25, 2011

[android-developers] Re: Listing all top level elements in strings.xml

Hi Kris,

Thanks for your response!
I was able to use this for discovering members contained in the
R.string class.

For others who may encounter this problem:

Field[] fields = getClassLoader().loadClass(getPackageName() + "/R
$string").getDeclaredFields();
for(Field field : fields) {
Log.v("TAG", "Field :" + field.getName() + " = " +
getResources().getString(field.getInt(null)));
}


On Sep 24, 4:13 pm, jpathak <jay.pat...@gmail.com> wrote:
> Hi Kris,
>
> Thanks for replying. The reason I want to do this is because there is
> a pre-build step in whichstrings.xmlis itself generated by another
> script and I want Java code to iterate through all strings in this
> xml. Perhaps as Kostya suggested I can use reflection, but I haven't
> tried it yet.
>
> On Sep 24, 1:53 pm, Kristopher Micinski <krismicin...@gmail.com>
> wrote:
>
>
>
>
>
>
>
> > On Sat, Sep 24, 2011 at 4:49 PM, jpathak <jay.pat...@gmail.com> wrote:
> > > Hi,
>
> > > I wanted my application to be able to discover what string resources
> > > (including string arrays, but only the name of the string array) it
> > > has, on startup at runtime. I didn't find a way to do this in the API
> > > docs, or perhaps I'm missing something. Can someone help ?
>
> > > Thanks,
> > > -Jay.
>
> > Why?  Why do you want to do this?  Perhaps that could give some better
> > advice without using a hack. Whatever you do, going through the
> >strings.xmlis *not* the answer :-).
>
> > Kris

--
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
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment