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

时间:2017-10-25 16:39:27

标签: android expandablelistview

我有一个带有自定义适配器的可扩展列表视图,可扩展列表的详细信息不会按顺序出现并在设备之间更改,如何为其提供一个不会更改的订单?

以下是其中一个细节的示例:

    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,......排序,但它会随机显示。

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您需要使用LinkedHashMap代替HashMap来保留广告订单

  

使用Hash表和Map接口的链表实现   可预测的迭代顺序。 This implementation differs from HashMap   因为它维护着一个贯穿所有链接的双向链表   条目。 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