Activity 页面
private int[][] tags = null;
private int a;
private int b;
protected void init() {
setContentView(R.layout.activity_tank_list_editor);
Intent intent = getIntent();
mGroup = intent.getStringArrayListExtra("groupData");
Bundle bundle = intent.getExtras();
SerializableMap mMap = (SerializableMap) bundle.get("childData");
mChild = mMap.getMap();
//这里a,b分别对应的是ExpandableListView父类和子类的个数,
a=50;
b=100;
tags = new int[a][b];
findView();
setView();
setListener();
}
private void setListener() {
//这里我们要给点击过的item 设置状态,
expandListView.setOnChildClickListener(new ExpandableListView.
OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
ExpandableListViewTankEditor.GroupChildHolder holder = (ExpandableListViewTankEd itor.GroupChildHolder) v.getTag();
//此处按钮可以用自定义checkBox,但是好像得解决抢占焦点的问题
if (holder.title.getTextColors().getDefaultColor() == getResources().getColor
(R.colo r.grayColor)) {
holder.title.setTextColor(getResources().getColor(R.color.icon_color));
holder.ll_icon.setBackground(getResources().getDrawable
(R.drawable.icon_background_circular));
holder.iv_select.setImageResource(R.drawable.select);
tags[groupPosition][childPosition] = 1;
} else {
holder.title.setTextColor(getResources().getColor(R.color.grayColor));
holder.ll_icon.setBackground(getResources().getDrawable
(R.drawable.icon_background_circular_gray));
holder.iv_select.setImageResource(R.drawable.no_select);
tags[groupPosition][childPosition] = 0;
}
edAdapter.setTags(tags);
//edAdapter.notifyDataSetChanged();
return false;
}
});
}
public class ExpandableListViewTankEditor extends BaseExpandableListAdapter {
private List<String> mGroup;
private Map<String, List<String>> mChild;
private Context context;
private int[][] tags = null;
public void setTags(int[][] tags) {
this.tags = tags;
}
public ExpandableListViewTankEditor(Context context, List<String> group,
Map<String, List<String>> child,int[][] tags) {
super();
this.context = context;
this.mGroup = group;
this.mChild = child;
this.tags=tags;
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
tags[i][j] = 0;
}
}
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
GroupChildHolder holder;
if (convertView == null) {
convertView = UIUtils.inflate(R.layout.item_tank_editor_adapter_child);
holder = new GroupChildHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.iv_child_icon);
holder.title = (TextView) convertView.findViewById(R.id.tv_child_title);
holder.desc = (TextView) convertView.findViewById(R.id.tv_child_desc);
holder.select = (LinearLayout) convertView.findViewById
(R.id.editor_select);
holder.iv_select = (ImageView) convertView.findViewById(R.id.iv_select);
holder.ll_icon = (LinearLayout) convertView.findViewById
(R.id.line1_icon);
convertView.setTag(holder);
} else {
holder = (GroupChildHolder) convertView.getTag();
}
holder.title.setText(mChild.get(mGroup.get(groupPosition)).get(childPosition));
if (tags[groupPosition][childPosition] == 1) {
holder.title.setTextColor(context.getResources().getColor
(R.color.icon_color));
holder.ll_icon.setBackground(context.getResources().getDrawable
(R.drawable.icon_background_circular));
holder.iv_select.setImageResource(R.drawable.select);
} else {
holder.title.setTextColor(context.getResources().getColor
(R.color.grayColor));
holder.ll_icon.setBackground(context.getResources().getDrawable
(R.drawable.icon_background_circular_gray));
holder.iv_select.setImageResource(R.drawable.no_select);
}
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
//默认是false,此处设为true
return true;
}
}