Reputation: 95
I have an expandable list view with custom adapter, the details of the expandable list doesn't appear in order and change from device to device, how to give it an order that doesn't change?
Here's an example of details of one of them:
public static HashMap<String, List<String>> getinfoE() {
HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();
List<String> m1 = new ArrayList<String>();
m1.add("Princess Noura Bint Abdulrahman University established Arabic Teaching Institute for Non-Arabic speakers on November 3, 2012, with the consent of the Custodian of the Two Holy Mosques King Abdullah bin Abdulaziz Al Saud, may God have mercy on him, and since that time the institute was keen to complete the vision and the necessary preparations to be a distinctive scientific edifice in teaching Arabic language for non-Arabic speakers.");
List<String> m2 = new ArrayList<String>();
m2.add("International Leadership in Arabic Language Teaching for non-Arabic speakers utilizing specialized programs and technologies.");
List<String> m3 = new ArrayList<String>();
m3.add("Learning and teaching Arabic language for Non-Arabic speakers in a distinctive academic environment having excellent, highly qualified and highly educated female faculty, by providing academic and training programs, that always consider the Saudi culture and human principles.");
List<String> m4 = new ArrayList<String>();
m4.add("-\tProviding students with high level language skills. \n" +
"-\tProviding students with the Saudi and Islamic culture for those who need it. \n" +
"-\tDeveloping the students educationally and personally throughout some supportive programs and workshops. \n" +
"-\tOffering material and moral support to the students to achieve projects that are helpful for the Arabic language and the institution. \n" +
"-\tProviding international social service by providing specialized programs to improve their individuals Arabic language for both general and specific purposes. \n" +
"-\tSupporting the cultural dialogue and diversity between different nations within the limits of human values. \n" +
"-\tEncouraging research and studies in the area of specialization.\n");
List<String> m5 = new ArrayList<String>();
m5.add("The Institute has expert female instructors who are specialized in Applied linguistics and teaching Arabic language as a second language. Moreover, it has a skilled administrative staff alongside with a great number of students with various nationalities.");
List<String> m6 = new ArrayList<String>();
m6.add("The Institute is considered as an international cultural gate in Saudi Arabia since its students come from different countries and cultures. Proudly, the institute contains different nationalities which belong to Africa, Asia, Europe, and North America.");
expandableListDetail.put("About The Institute", m1);
expandableListDetail.put("The Institute vision", m2);
expandableListDetail.put("The Institute mission", m3);
expandableListDetail.put("The Institute goals", m4);
expandableListDetail.put("The Institute faculties", m5);
expandableListDetail.put("The Institute students", m6);
This doesn't appear in the order i want,i want it to be ordered as m1, m2, m3, ... but it keep displayed randomly.
How to solve this?
Upvotes: 0
Views: 39
Reputation: 37404
You need to use LinkedHashMap
instead of HashMap
to keep the insertion order
Hash table and linked list implementation of the Map interface, with predictable iteration order.
This implementation differs from HashMap
in that it maintains a doubly-linked list running through all of its entries.This linked list defines the iteration ordering, which is
normally the order in which keys were inserted into the map
(insertion-order). Note that insertion order is not affected if a key
is re-inserted into the map
.
so
Map<String, List<String>> expandableListDetail = new LinkedHashMap<String, List<String>>();
// = new LinkedHashMap<String, List<String>>(6);
// can add a little efficienty by giving initial capacity
// otherwise it will be 16 where extra 10 , which you might not required
Upvotes: 1