android - Defining a String array in XML vs building it dynamically -


i tryin build string array of 60 strings not sure 1 better performance:

in code dynamically:

minutevalues = new string[60];  string minutesbefore = getresources().getstring(r.string.minutes_before);  (int = 0; < 60; ++i) {     minutevalues[i] = + 1 + minutesbefore; } 

or in xml statically:

<array name="minutes_before_array">     <item>1 minute before</item>     <item>2 minutes before</item>     <item>3 minutes before</item>     <item>4 minutes before</item>     <item>5 minutes before</item>     .     .     .     <item>60 minutes before</item> </array> 

there should no significant performance difference whatsoever.

here cleaner way of doing it, though:

<string name="minutes_before">%d minutes before</string> 

and use in code:

int minutes = getnumberofminutessomehow(); string timestring = getresources().getstring(r.string.minutes_before, minutes); 

this uses [the alternate version](http://developer.android.com/reference/android/content/res/resources.html#getstring(int, java.lang.object...)) of getstring.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -