Like the rest of the people that have responded, here, I'm a bit
dubious about this use case.  It seems to me that these strings are
either essentially part of the code, in which case you should use R...
references to them, or part of the data, in which case they should be
in a property file, DB, or some such thing.  Just because you can get
strings into your program using the R... mechanism, doesn't mean it is
the right way to get every string there.

That said, the *only* safe way I can think of, to do this, is
reflection.  Use Class.getDeclaredFields() to get an array of fields
in the class.  Walk the array, looking for the ones you care about,
adding the name and value to a Map.  ...or something like that.

Again, though, wouldn't it be easy to open a file and read one string
per line, into an array?

-blake
Programming Android: http://ofps.oreilly.com/titles/9781449389697/

On Sep 1, 4:24 am, LiTTle <littlep...@gmail.com> wrote:
> Hi,
>
> I found a way to call the variables from R file which are generated
> automatically without using their names but through a for block. I
> believe that the algorithm is something like that. I don't say that
> this is the algorithm but I imagine it!
>
> ///////////////////////////////////////////////////////////////////
> items = array of variables;
> i=0;
> for ( file: xml_files ){
>   items[i] = read the first item from file;
>   i++;
>
> }
>
> sort items;
> for (item:items){
>   write to R file the contents of xml file where the item variable
> exists
>
> }
>
> /////////////////////////////////////////////////////////////////
> And now a little (actually I mean a lot) of my code. 2 xml files are
> following (zzzShops_18_29.xml,
> zzzShops_18_28.xml).
> ////////////////  zzzShops_18_29.xml  /////////////////////////////
> <?xml version="1.0" encoding="utf-8"?>
> <resources>
> <!-- Write the shops using alphabetical order to this array-->
> <!-- Change the value Shops_XX_XX_count @ GuideActivity if the string
> arrays
>                 here (and to every zzzShops_XX_XX.xml file) get
> increased or
> decreased.  -->
>         <string-array name="aaaShops_18_29_name">
>         <item>Value_Name</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_29_street">
>         <item>Value_Street</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_29_tel">
>         <item>Value_Tel</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_29_mob">
>         <item>Value_Mob</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_29_fax">
>         <item>Value_Fax</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_29_site">
>         <item>Value_Site</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_29_email">
>         <item>Value_Email</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_29_map">
>         <item>x,x</item><!-- 0 -->
>     </string-array>
> </resources>
> /////////////////////////////////////////////////////////////
> ////////////////  zzzShops_18_28.xml  /////////////////////////////
> <?xml version="1.0" encoding="utf-8"?>
> <resources>
> <!-- Write the shops using alphabetical order to this array-->
> <!-- Change the value Shops_XX_XX_count @ GuideActivity if the string
> arrays
>                 here (and to every zzzShops_XX_XX.xml file) get
> increased or
> decreased.  -->
>         <string-array name="aaaShops_18_28_name">
>         <item>Value_Name</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_28_street">
>         <item>Value_Street</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_28_tel">
>         <item>Value_Tel</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_28_mob">
>         <item>Value_Mob</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_28_fax">
>         <item>Value_Fax</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_28_site">
>         <item>Value_Site</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_28_email">
>         <item>Value_Email</item><!-- 0 -->
>     </string-array>
>     <string-array name="aaaShops_18_28_map">
>         <item>x,x</item><!-- 0 -->
>     </string-array>
> </resources>
> //////////////////////////////////////////////////////////
> The contents of the R file depending on the previous files are:
> /////////////////////////////////////////////////////////////
> public static final int aaaShops_18_28_email=0x7f04018b;
>         /**  0
>          */
>         public static final int aaaShops_18_28_fax=0x7f040189;
>         /**  0
>          */
>         public static final int aaaShops_18_28_map=0x7f04018c;
>         /**  0
>          */
>         public static final int aaaShops_18_28_mob=0x7f040188;
>         /**  ?????-?????? / ??????????
>  Write the shops using alphabetical order to this array
>  Change the value Shops_XX_XX_count @ GuideActivity if the string
> arrays
>                 here (and to every zzzShops_XX_XX.xml file) get
> increased or
> decreased.
>  0
>          */
>         public static final int aaaShops_18_28_name=0x7f040185;
>         /**  0
>          */
>         public static final int aaaShops_18_28_site=0x7f04018a;
>         /**  0
>          */
>         public static final int aaaShops_18_28_street=0x7f040186;
>         /**  0
>          */
>         public static final int aaaShops_18_28_tel=0x7f040187;
>         /**  0
>          */
>         public static final int aaaShops_18_29_email=0x7f040193;
>         /**  0
>          */
>         public static final int aaaShops_18_29_fax=0x7f040191;
>         /**  0
>          */
>         public static final int aaaShops_18_29_map=0x7f040194;
>         /**  0
>          */
>         public static final int aaaShops_18_29_mob=0x7f040190;
>         /**  ?????-?????? / ???????????????????
>  Write the shops using alphabetical order to this array
>  Change the value Shops_XX_XX_count @ GuideActivity if the string
> arrays
>                 here (and to every zzzShops_XX_XX.xml file) get
> increased or
> decreased.
>  0
>          */
>         public static final int aaaShops_18_29_name=0x7f04018d;
>         /**  0
>          */
>         public static final int aaaShops_18_29_site=0x7f040192;
>         /**  0
>          */
>         public static final int aaaShops_18_29_street=0x7f04018e;
>         /**  0
>          */
>         public static final int aaaShops_18_29_tel=0x7f04018f;
> ///////////////////////////////////////////////
> Take a look. There is an alphabetical order and the hex values have
> specific values.
> Actually if you see, you can do the following!
> ΠΧ aaaShops_18_29_street=aaaShops_18_29_name+1
>
> Is this right? Do you suggest to use it?

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

Reply via email to