【发布时间】:2023-03-19 19:50:01
【问题描述】:
我在 ExpandableListView 中有一个用户列表,现在我有 2 组列表,现在我正在尝试创建一个 ArrayList,它将在我单击用户时添加数据,所以如果有2组学校,我点击每一个学生我的数组中应该有2个位置,每个组包含其各自的用户,我的问题是,我的数组有2个位置,但它没有分隔学生:
我想要的是这个:
学校 A:
学生1被选中
学生2
学生3被选中
学校 B:
学生4
学生5被选中
导致:
[0]-> 学生 1,3 [1] ->学生 5
这是我目前尝试过的:
mGpsEscolas = new GPSEscolas();
mArrayEscolas = new ArrayList<GPSEscolas>();
aMap = new HashMap<String, GPSEscolas>();
ExpandList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(final ExpandableListView parent, View v, final int groupPosition, final int childPosition, final long id) {
ExpAdapter.setClicked(groupPosition, childPosition);
index = parent.getFlatListPosition(ExpandableListView.getPackedPositionForChild(groupPosition, childPosition));
parent.setItemChecked(index, true);
parent.setSelectedChild(groupPosition, childPosition, true);
parent.getChildAt(index);
IdAlunos = String.valueOf(mMainRest.mArrayList.get(groupPosition).getalunos().get(childPosition).getId_aluno());
IdEscola = String.valueOf(mMainRest.mArrayList.get(groupPosition).getId_escola());
ids_alunos.add(IdAlunos);
notificar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int groupCount = ExpandList.getExpandableListAdapter().getGroupCount();
for (int group = 1; group <= groupCount; group++) {
int gcount = ExpandList.getExpandableListAdapter().getChildrenCount(groupPosition);
mArrayEscolas = new ArrayList<GPSEscolas>();
for (int child = 1; child <= gcount; child++) {
mGpsEscolas.setIds_alunos(String.valueOf(IdAlunos).substring(1));
mGpsEscolas.setId_escola(Integer.valueOf(IdEscola));
mGpsEscolas.setLatitude(latitudeEscola);
mGpsEscolas.setLongitude(longitudeEscola);
mGpsEscolas.setDistancia(mMainRest.RaioEscola);
mArrayEscolas.add(mGpsEscolas);
if (ExpAdapter.isChildSelectable(groupPosition, childPosition)) {
aMap.put(ExpandList.getExpandableListAdapter().getChildId(group, child), mArrayEscolas);
}
}
}
}
});
return false;
}
});
【问题讨论】:
-
您是否尝试过使用自定义 ExpandableListAdapter?跟踪所有内容可能更容易,包括“onChecked”侦听器以及附加到适配器的 ArrayList 对象。网上有不少例子:这是适配器的YouTube视频youtu.be/-tAH1hW_tYc
-
@c0d3blooded 我正在使用自定义 ExpandableListAdapter
-
您需要在 GPSEscolas(parent) 模型类中创建学生(子)模型类的数组列表,并在单击或选择时管理一些布尔值。请关注此javacodegeeks.com/2013/06/…。如果您需要进一步的帮助,请告诉我。
标签: java android arrays multidimensional-array arraylist