Skip to content

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

@PareshMayani

Description

@PareshMayani

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions