2016-11-01 4 views
-2

ExpandableListView를 사용하고 있으며 배열 목록에 몇 가지 목록을 설정했습니다.
내가는 특정 순서로 그들을 설정 :ExpandableListView 배열 목록을 내가 넣은 순서대로 유지하지 않습니다.

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

하지만 순서가

로 복귀 할 무엇도
posh vehicles, company, days of the week, topgear vehicles 

이 사람이 나를 여기에 문제를 알아낼 수 있습니다 는 코드 I는 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; 
+0

또 다른 힌트 : 논리에 요일 이름을 기억할 필요가 없습니다. 대신 Javas 날짜/캘린더 API를 사용해야합니다.이 API는 Javas 날짜/캘린더 API를 사용해야합니다. – GhostCat

+0

언제나처럼 @GhostCat는 중복 된 질문을 보게 될 것입니다 –

답변

1

HashMap은 삽입 순서를 유지하지 않습니다.

당신은 (HashMap를 확장하는) 대신 LinkedHashMap를 사용할 수 있습니다

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

는 또한 왼쪽 Map 당신이있는 경우에 작동하는 다이아몬드 연산자 (<>)의 인터페이스 이름을 사용 적어도 자바 7

+1

나는 그 명백한 "dup"질문에 대답 할 때 downvote에 유혹을 느낍니다. 그러나 적어도 다이아몬드 연산자를 사용하는 것에 대한 좋은 세부 사항을 넣어 두지는 않을 것입니다 ;-) – GhostCat