BaseExpandableListAdapter中的多个无线电组的保持器无法正常工作

时间:2019-04-27 22:16:55

标签: java android

上下滚动RadioGroup值时不记得了。 我为每个RadioGroup和RadioButton设置了唯一的ID。你可以看到 this video shows how the code behaves

public View getChildView(final int listPosition, final int expandedListPosition,
                                 boolean isLastChild, View convertView, ViewGroup parent) {
            final String expandedListText = (String) getChild(listPosition, expandedListPosition);
            View rowView = convertView;
            if (rowView == null) {
                LayoutInflater layoutInflater = (LayoutInflater) this.context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                rowView = layoutInflater.inflate(R.layout.list_item_expa_radio, parent, false);
                holder = new MatrixHolder();
                holder.group = (RadioGroup) rowView.findViewById(R.id.radioOtazky);
                holder.group.clearCheck();
                holder.neni = (RadioButton) rowView.findViewById(R.id.neni);
                holder.slaba = (RadioButton) rowView.findViewById(R.id.slaba);
                rowView.setTag(holder);
            }else {
                holder = (MatrixHolder) rowView.getTag();
            }
            holder.group.setOnCheckedChangeListener(null);
            if(mSelections.get(expandedListPosition) > 0) {
    holder.group.check(mSelections.get(expandedListPosition));
            }
            holder.group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup radioGroup, int i) {
                mSelections.put(expandedListPosition, radioGroup.getCheckedRadioButtonId());
                notifyDataSetChanged();
                }
            });
            int groupId = Integer.parseInt(separated[0])+10;
            int neniId = Integer.parseInt(separated[0])+100;
            int slabaId = Integer.parseInt(separated[0])+200;
            holder.group.setTag("group_"+groupId);
            holder.group.setId(groupId);
            holder.neni.setId(neniId);
            holder.neni.setText("neni"+neniId);
            holder.slaba.setId(slabaId);
            holder.slaba.setText("slaba"+slabaId);

 return rowView;
}

0 个答案:

没有答案