ExpandableListView数组列表不会按照我放的顺序保留

时间:2016-11-01 19:06:38

标签: java android arraylist hashmap expandablelistview

我正在使用ExpandableListView,我在数组列表中设置了一些列表 我将它们按照以下顺序设置:

company, day of the week, posh vehicles, topgear vehicles

但我做了什么订单还原为

posh vehicles, company, days of the week, topgear vehicles

有人能帮我解决问题,这里是我用于stringArray的代码吗?

 public static HashMap<String, List<String>> getData() {

    HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();

    List<String> listDataHeader = new ArrayList<String>();
    // Adding child data
    listDataHeader.add("Company");
    listDataHeader.add("Please pick a day");
    listDataHeader.add("Posh Vehicles");
    listDataHeader.add("TopGear Vehicles");

    List<String> CompanyName = new ArrayList<>();
    CompanyName.add("Posh limos");
    CompanyName.add("TopGear limos");

    List<String> daysOftheWeek = new ArrayList<>();
    daysOftheWeek.add("Monday");
    daysOftheWeek.add("Tuesday");
    daysOftheWeek.add("Wednesday");
    daysOftheWeek.add("Thursday");
    daysOftheWeek.add("Thursday");
    daysOftheWeek.add("Friday");
    daysOftheWeek.add("Saturday");
    daysOftheWeek.add("Sunday");

    List<String> poshvehicles = new ArrayList<>();
    poshvehicles.add("Posh H2 limo");
    poshvehicles.add("Iveco party bus");
    poshvehicles.add("Merc party bus ");
    poshvehicles.add("Party coach");

    List<String> topGearVehicles = new ArrayList<>();
    topGearVehicles.add("TopGear H2 limo");
    topGearVehicles.add("TopGear party bus");

    expandableListDetail.put(listDataHeader.get(0),CompanyName);
    expandableListDetail.put(listDataHeader.get(1),daysOftheWeek);
    expandableListDetail.put(listDataHeader.get(2),poshvehicles);
    expandableListDetail.put(listDataHeader.get(3),topGearVehicles);

    return expandableListDetail; 

1 个答案:

答案 0 :(得分:1)

HashMap不保留广告订单。

您可以改为使用LinkedHashMap(扩展HashMap):

Map<String, List<String>> expandableListDetail = new LinkedHashMap<>();

如果您至少拥有Java 7,我还使用左侧Map的接口名称和菱形运算符(<>)。