2017-12-27 120 views
0

我是Android新手,正在開發一個Event應用程序。該應用程序有一個子事件,所以我使用了可擴展列表視圖,但其順序與Arraylist對象順序不同。我已經使用排序功能&其工作,但我需要訂購我的訂單。如何將訂單設置爲Expandablelistview?

如何解決這個問題?

DataPump.java

public class ExpandableListDataPump { 
    public static HashMap<String, List<String>> getData(ArrayList<Guide> guides) { 
     HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>(); 

     List<String> parent = new ArrayList<String>(); 
     for (int i = 0; i < guides.size(); i++) { 
      parent=new ArrayList<>(); 
      Guide guide=guides.get(i); 
//   Log.e("size***",guide.getName()+"-"+ String.valueOf(guide.getItem_list().size())); 

      if (guide.getItem_list().isEmpty()){ 

      }else{ 
       for (int j=0;j<guide.getItem_list().size();j++){ 
        parent.add(guide.getItem_list().get(j).getName()); 
//     Log.e("add****", String.valueOf(guides.get(i).getItem_list().get(j).getName())); 

       } 

      } 
      expandableListDetail.put(guide.getName(), parent); 

     } 
在Activity類

expandableListView = (ExpandableListView) findViewById(R.id.exLv_events); 
     expandableListDetail = ExpandableListDataPump.getData(guideArrayList); 
     expandableListTitle = new ArrayList<String>(expandableListDetail.keySet()); 
//  Collections.sort(expandableListTitle); 

     expandableListAdapter = new CustomExpandableListAdapter(this, expandableListTitle, expandableListDetail); 
     expandableListView.setAdapter(expandableListAdapter); 
+1

分享您的代碼和錯誤日誌? – R2R

+0

無錯誤日誌R2R –

+0

_I需要訂購我的訂單嗎?_您需要在列表項目中對您的子項目進行排序? – SripadRaj

回答

0

我改變HashMap來LinkedHashMap的,那麼問題就解決了,

代碼snipts, datapump.java

public class ExpandableListDataPump { 
    public static LinkedHashMap<String, List<String>> getData(ArrayList<Guide> guides) { 
     LinkedHashMap<String, List<String>> expandableListDetail = new LinkedHashMap<>(); 

     List<String> parent = new ArrayList<String>(); 
     for (int i = 0; i < guides.size(); i++) { 
      parent=new ArrayList<>(); 
      Guide guide=guides.get(i); 
      Log.e("dpump***",guide.getName()); 

      if (guide.getItem_list().isEmpty()){ 

      }else{ 
       for (int j=0;j<guide.getItem_list().size();j++){ 
        parent.add(guide.getItem_list().get(j).getName()); 
//     Log.e("add****", String.valueOf(guides.get(i).getItem_list().get(j).getName())); 

       } 

      } 
//   expandableListDetail.put(guide.getName(), parent); 
      expandableListDetail.put(guide.getName(), parent); 
      Log.e("size###", String.valueOf(expandableListDetail.size())); 

     } 

     return expandableListDetail; 
    } 
} 

和活動

LinkedHashMap> expandableListDetail;

和裝載時,

expandableListView = (ExpandableListView) findViewById(R.id.exLv_events); 
     expandableListDetail = ExpandableListDataPump.getData(guideArrayList); 
     expandableListTitle = new ArrayList<String>(expandableListDetail.keySet()); 
     expandableListAdapter = new CustomExpandableListAdapter(this, expandableListTitle, expandableListDetail); 
     expandableListView.setAdapter(expandableListAdapter); 
相關問題