1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
| private List<frag_settings_categories> data;
private HashMap<frag_settings_categories,></frag_settings_categories,><frag_settings_categories>> child;
private Context context;
public Frag_Settings_Categories_Adapter(Context context, List<frag_settings_categories> items, HashMap<frag_settings_categories,></frag_settings_categories,><frag_settings_categories>> listChildData) {
this.context = context;
this.data = items;
this.child = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this.child.get(this.data.get(groupPosition)).get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
// //////////////////// CHILD ITEM
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.frag_settings_row_detail_02_categories_row, null);
}
ViewHolder holder;
holder = new ViewHolder();
holder.rowText = (TextView) convertView.findViewById(R.id.frag_settings_row_detail_02_categories_row_title);
holder.rowChk = (CheckBox) convertView.findViewById(R.id.frag_settings_row_detail_02_categories_row_check);
// http://stackoverflow.com/questions/12647001/listview-with-custom-adapter-containing-checkboxes
holder.rowChk.setTag(String.valueOf(groupPosition) + "|" + String.valueOf(childPosition)); // store the List<>position in TAG
holder.rowChk.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String tag_txt = buttonView.getTag().toString();
int delimiter_pos =tag_txt.indexOf("|");
int head_id =Integer.parseInt(tag_txt.substring(0,delimiter_pos));
int child_id = Integer.parseInt(tag_txt.substring(delimiter_pos+1));
child.get(data.get(head_id)).get(child_id).setIs_selected(isChecked); // use of List<>position
}
});
// get CHILD items (search via HEAD item)
List<frag_settings_categories> single = child.get(data.get(groupPosition));
// >>>>>>>>>> get - which item the view requires via childPosition
holder.rowText.setText(single.get(childPosition).getTitle());
if (single.get(childPosition).getIs_selected())
holder.rowChk.setChecked(true);
else
holder.rowChk.setChecked(false);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this.child.get(this.data.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return this.data.get(groupPosition);
}
@Override
public int getGroupCount() {
return this.data.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
// //////////////////// HEAD ITEM
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.frag_settings_row_detail_02_categories_row, null);
}
ViewHolder holder;
holder = new ViewHolder();
holder.rowText = (TextView) convertView.findViewById(R.id.frag_settings_row_detail_02_categories_row_title);
holder.rowChk = (CheckBox) convertView.findViewById(R.id.frag_settings_row_detail_02_categories_row_check);
// http://stackoverflow.com/questions/12647001/listview-with-custom-adapter-containing-checkboxes
holder.rowChk.setTag(Integer.valueOf(groupPosition)); // store the List<>position in TAG
holder.rowChk.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
data.get((Integer) buttonView.getTag()).setIs_selected(isChecked); // use of List<>position
notifyDataSetChanged(); //refresh view
}
});
holder.rowText.setText(data.get(groupPosition).getTitle());
if (data.get(groupPosition).getIs_selected()) {
holder.rowChk.setChecked(true);
manipulate_children_value((groupPosition),true);
} else {
holder.rowChk.setChecked(false);
manipulate_children_value(groupPosition,false);
}
return convertView;
}
private void manipulate_children_value(int head_position, Boolean val) { // List<frag_settings_categories> x = child.get(data.get(head_position)); // // for (int i = 0; i < x.size();="" i++)="" {="" child.get(data.get(head_position)).get(i).setis_selected(val);="" }="" similar="" for="" (frag_settings_categories="" x="" :="" child.get(data.get(head_position)))="" {="" x.setis_selected(val);="" }="" }="" @override="" public="" void="" notifydatasetchanged()="" {="" super.notifydatasetchanged();="" }="" @override="" public="" boolean="" hasstableids()="" {="" http://stackoverflow.com/a/18217552/1320686="" return="" true;="" }="" @override="" public="" boolean="" ischildselectable(int="" groupposition,="" int="" childposition)="" {="" return="" true;="" }="" class="" viewholder="" {="" textview="" rowtext;="" checkbox="" rowchk;="" }="" }="" frag_settings_categories.java="" public="" class="" frag_settings_categories="" {="" private="" int="" id;="" private="" string="" title;="" private="" boolean="" is_selected;="" public="" frag_settings_categories(long="" id,string="" title,="" boolean="" is_selected){="" this.id="(int)" id;="" this.title="title;" this.is_selected="is_selected;" }="" public="" int="" getid()="" {="" return="" id;="" }="" public="" void="" setid(int="" id)="" {="" this.id="id;" }="" public="" string="" gettitle()="" {="" return="" title;="" }="" public="" void="" settitle(string="" title)="" {="" this.title="title;" }="" public="" boolean="" getis_selected()="" {="" return="" is_selected;="" }="" public="" void="" setis_selected(boolean="" is_selected)="" {="" this.is_selected="is_selected;" }="" }="" ```="" x.size();="" i++)="" {="" child.get(data.get(head_position)).get(i).setis_selected(val);="" }="" similar="" for="" (frag_settings_categories="" x="" :="" child.get(data.get(head_position)))="" {="" x.setis_selected(val);="" }="" }="" @override="" public="" void="" notifydatasetchanged()="" {="" super.notifydatasetchanged();="" }="" @override="" public="" boolean="" hasstableids()="" {="" http://stackoverflow.com/a/18217552/1320686="" return="" true;="" }="" @override="" public="" boolean="" ischildselectable(int="" groupposition,="" int="" childposition)="" {="" return="" true;="" }="" class="" viewholder="" {="" textview="" rowtext;="" checkbox="" rowchk;="" }="" }="" frag_settings_categories.java="" public="" class="" frag_settings_categories="" {="" private="" int="" id;="" private="" string="" title;="" private="" boolean="" is_selected;="" public="" frag_settings_categories(long="" id,string="" title,="" boolean="" is_selected){="" this.id="(int)" id;="" this.title="title;" this.is_selected="is_selected;" }="" public="" int="" getid()="" {="" return="" id;="" }="" public="" void="" setid(int="" id)="" {="" this.id="id;" }="" public="" string="" gettitle()="" {="" return="" title;="" }="" public="" void="" settitle(string="" title)="" {="" this.title="title;" }="" public="" boolean="" getis_selected()="" {="" return="" is_selected;="" }="" public="" void="" setis_selected(boolean="" is_selected)="" {="" this.is_selected="is_selected;" }="" }=""></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories></frag_settings_categories>
|