Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization: List should contain ID, name, code and other details #4

Open
PareshMayani opened this issue Jul 15, 2015 · 3 comments
Open

Comments

@PareshMayani
Copy link
Contributor

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]);
}

Optimized solution:

<resources>    
<string-array name="countries_array">        
  <item>
    <name>Bahrain</name>
    <code>12345</code>
  </item>
...  
</string-array>
</resources>

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

@vinaygaba
Copy link
Owner

@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!

@PareshMayani
Copy link
Contributor Author

Keep the current lists as same, just add a single list with all the details belonging to the particular country!

@AkshayChordiya
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants