You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This point is about to optimize the code you are using. Instead of referring to two or more different lists separately, there should be a single list contains all the items and each item should contain code, name, ID, language, etc. details (i.e. required details)
Yes the current solution which is like preparing an arraylist of string directly is best, but it's a good solution when you are getting values from different array lists, because by change if someone or you delete an item from a particular list then items count won't be matched and so loop break!
Current:
String[] us_state_codes = getResources().getStringArray(R.array.us_state_codes);
String[] us_state = getResources().getStringArray(R.array.us_states);
final Map<String, String> m = new HashMap<String, String>();
for(int i=0;i<us_state_codes.length();i++){
m.put(us_state_codes[i],us_states[i]);
}
@PareshMayani I quite like this idea. Honestly I didn't know this was possible to do. I will make these changes for sure. Might take some time but will get to it. Thanks for sharing!
@vinaygaba@PareshMayani
The problem to go with the above pattern is, it removes the simplicity of using string-array and switches to use of XML Parsers.
This point is about to optimize the code you are using. Instead of referring to two or more different lists separately, there should be a single list contains all the items and each item should contain code, name, ID, language, etc. details (i.e. required details)
Yes the current solution which is like preparing an arraylist of string directly is best, but it's a good solution when you are getting values from different array lists, because by change if someone or you delete an item from a particular list then items count won't be matched and so loop break!
Current:
Optimized solution:
And solution should be like parsing XML and preparing list of objects. More details: http://stackoverflow.com/questions/9568700/android-resource-an-array-to-store-country-name-country-code
The text was updated successfully, but these errors were encountered: