I'm trying to figure out why my items from my listview are displayed in a wrong order. I think this is related to the iterator but I'm not sure about that.
This is the code from my activity:
//String Capitole
String Articolul1 = getResources().getString(R.string.dispozitiiGeneraleArt_1);
String Articolul2 = getResources().getString(R.string.dispozitiiGeneraleArt_2);
String Articolul3 = getResources().getString(R.string.dispozitiiGeneraleArt_3);
//ListView Set
ListView listDispGen = (ListView) findViewById(R.id.dispozitiigeneralelist);
HashMap<String, String> articolExplicatii = new HashMap<>();
articolExplicatii.put(" Art.1", Articolul1);
articolExplicatii.put(" Art.2", Articolul2);
articolExplicatii.put(" Art.3", Articolul3);
List<HashMap<String, String>> listItems = new ArrayList<>();
SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.dispgeneralelist,
new String[]{"First Line", "Second Line"},
new int[]{R.id.main_item, R.id.sub_item});
Iterator it = articolExplicatii.entrySet().iterator();
while(it.hasNext()) {
HashMap<String, String> resultsMap = new HashMap<>();
Map.Entry pair = (Map.Entry)it.next();
resultsMap.put("First Line", pair.getKey().toString());
resultsMap.put("Second Line", pair.getValue().toString());
listItems.add(resultsMap);
}
listDispGen.setAdapter(adapter);
The main problem is that when I'm running the app the items are not displayed in the correct order like: Art.1, Art.2....Art.9 but they are displayed random like Art.3, Art.1, Art.3 etc.