如何将订单设置为Expandablelistview?

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

回答:

我改变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);

以上是 如何将订单设置为Expandablelistview? 的全部内容, 来源链接: utcz.com/qa/264413.html

回到顶部