expandlist
.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
// 只展开一个
for (int i =0, count =expandlist.getCount(); i < count; i++) {
if (groupPosition != i) {
expandlist.collapseGroup(i);
}
}
}
});
expandlist
.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent,
View v, int groupPosition, int childPosition,
long id) {
PresetTerminalDataAdapter.ViewHolder viewHolder = (PresetTerminalDataAdapter.ViewHolder) v.getTag();
if (viewHolder.child_check!=null){
viewHolder.child_check.toggle();
}
if (viewHolder.child_check.isChecked()) {
isSelectedList.get(groupPosition).put(
childPosition, 3);
}else {
isSelectedList.get(groupPosition).put(
childPosition, 1);
}
getSelectCount();
adapter.notifyDataSetChanged();
return false;
}
});
selectall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (groups.length>0) {
for (int i =0; i
for (int k =0; k
// for (int k = 0; k < groups[i].length(); k++) {
if (selectall.isChecked()){
isSelectedList.get(i).put(k,3);
selectall.setButtonDrawable(R.drawable.zone_select_pressed);
}else {
isSelectedList.get(i).put(k,1);
selectall.setButtonDrawable(R.drawable.zone_select_normal);
}
}
}
}
getSelectCount();
adapter.notifyDataSetChanged();
}
});
}
private void getSelectCount(){
int allcount=0;
for (int i=0;i
allcount=allcount+childs[i].length;
}
Log.d("aaa","allcount="+allcount);
int selectcount=0;
if (groups.length>0) {
for (int i =0; i
for (int k =0; k
//// for (int k = 0; k < groups[i].length(); k++) {
//
// if (selectall.isChecked()){
// isSelectedList.get(i).put(k,3);
// selectall.setButtonDrawable(R.drawable.zone_select_pressed);
// select_group=groups.length;
//// select_group=0;
// }else {
// isSelectedList.get(i).put(k,1);
// selectall.setButtonDrawable(R.drawable.zone_select_normal);
// select_group=0;
// }
if (isSelectedList.get(i).get(k)==3){
selectcount++;
}
}
}
}
if ( selectcount==allcount){
selectall.setButtonDrawable(R.drawable.zone_select_pressed);
selectall.setChecked(true);
}else {
selectall.setButtonDrawable(R.drawable.zone_select_normal);
selectall.setChecked(false);
}
Log.d("aaa","selectcount="+selectcount);
}
holder.group_check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int flag =0;
if (holder.group_check.isChecked()){
flag =3;
}else {
flag =1;
}
for (int i =0, size =isSelectedList.get(groupPosition).size(); i < size; i++) {
isSelectedList.get(groupPosition).put(i, flag);
}
notifyDataSetChanged();
Log.d("aaa","allcount=" +expandlist.getChildCount());
getSelectCount();
}
});
ExpandableListView.checkbox.setOnClickListener
holder.group_check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int flag =0;
if (holder.group_check.isChecked()){
flag =3;
}else {
flag =1;
}
for (int i =0, size =isSelectedList.get(groupPosition).size(); i < size; i++) {
isSelectedList.get(groupPosition).put(i, flag);
}
notifyDataSetChanged();
Log.d("aaa","allcount=" +expandlist.getChildCount());
getSelectCount();
}
获取选择的数量
private void getSelectCount(){
int allcount=0;
for (int i=0;i
allcount=allcount+childs[i].length;
}
Log.d("aaa","allcount="+allcount);
int selectcount=0;
if (groups.length>0) {
for (int i =0; i
for (int k =0; k
if (isSelectedList.get(i).get(k)==3){
selectcount++;
}
}
}
}
if ( selectcount==allcount){
selectall.setButtonDrawable(R.drawable.zone_select_pressed);
selectall.setChecked(true);
}else {
selectall.setButtonDrawable(R.drawable.zone_select_normal);
selectall.setChecked(false);
}
Log.d("aaa","selectcount="+selectcount);
}