我隐藏了ExpandableListView中的复选框,但expandableListview无法正常工作

时间:2016-02-11 09:57:21

标签: android checkbox expandablelistview

  

我使用以下ExpandableListView方法

创建了getView
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
                     View convertView, ViewGroup parent) {
Group_Items gr = (Group_Items) getGroup(groupPosition);
long group_id = getGroupId(groupPosition);

if (convertView == null) {
    LayoutInflater inf = (LayoutInflater) context
            .getSystemService(context.LAYOUT_INFLATER_SERVICE);
    convertView = inf.inflate(R.layout.expandable_group_items, null);

    // adding onClick listener on CheckBox for the very first time
    chk=(CheckBox) convertView.findViewById(R.id.chk);
    chk.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int position = (int) v.getTag();
            mSelections.put(position, !mSelections.get(position, false));
            ((CheckBox)v).setChecked(mSelections.get(position, false));
        }
    });
}

TextView title = (TextView) convertView.findViewById(R.id.title);
title.setText(gr.getName());
CheckBox chk=(CheckBox) convertView.findViewById(R.id.chk);
chk.setTag(groupPosition);
// reassigning checkbox to its ticked state
chk.setChecked(mSelections.get(groupPosition, false));

if(groupPosition==2) { ch.setVisibility(View.GONE); } return convertView; }

我使用上述if(groupPosition==2)方法隐藏了来自CheckBox的第三项ExpandablelistView,但是......

  

当我展开FirstSecond时,我面临另一个问题,然后CheckBoxes位置会自动更改

所以我现在很困惑如何处理这个错误

Here is my app 你可以查一下,请帮帮我

1 个答案:

答案 0 :(得分:0)

  

伙计们,我在这里尝试了以下答案:

 if(groupPosition==2) {
        chk.setVisibility(View.GONE);
        return convertView;
    }
    else {
        chk.setVisibility(View.VISIBLE);
        return convertView;
    }