订购自定义可扩展列表视图内容

Order a custom expandable list view contents

我有一个带有自定义适配器的可扩展列表视图,可扩展列表的详细信息没有按顺序显示,并且随着设备的不同而变化,如何给它一个不变的顺序?

以下是其中之一的详细信息示例:

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

这没有按我想要的顺序出现,我希望它按 m1、m2、m3...排序,但它一直随机显示。

如何解决?

您需要使用 LinkedHashMap 而不是 HashMap 来保持插入顺序

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.

所以

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