隐藏Android中自定义ExpandableListview的特定复选框

时间:2016-02-11 05:41:22

标签: android expandablelistview

  

我使用ExpandableListView在Android中创建了自定义checkBox我添加了8个标题,并希望隐藏或禁用第8个checkbox。我如何隐藏或禁用它。

我在ExpandableListView

中添加了项目
private ArrayList<Group_Items> setAllData() {

    String group_titles[] = {
            "Payment of Employer and employees contribution",
            "Monthly Return Filing in Form 5 and Declaration in form 2",
            "Monthly Return Filing in Form 10",
            "Monthly Return Filing in Form 12",
            "Statement of Recovery from contractor",
            "Annual Return in Form 6A",
            "Submission of contribution card of employees leaving services",
            "Renewal of contribution card of an employee by filing Form 3 & 3A"};

    String child_info[] = {
            "We have deployed secured web services framework in accordance with OASIS standards. Please refer the user manual (Secured Web service user manual) under the help section and do the necessary changes at your end to start consuming the same. Existing web services shall be discontinued w.e.f 1-Dec-2015.",
            "Return of employees qualifying for membership",
            "Return of members leaving the services during the month",
            "Statement of contribution",
            "Self Explanatory",
            "Consolidated annual contribution statement",
            "Self Explanatory",
            "Self Explanatory"};

    String dates[] = {
            "15th of Next Month + 5 Days Grace period",
            "15th of Next Month",
            "15th of Next Month",
            "25th of Next Month",
            "7th of Next Month",
            "30th April",
            "20th of Next Month",
            "Within one month on the expiry of contribution card currancy to the commissioner",};

    ArrayList<Group_Items> list = new ArrayList<Group_Items>();
    ArrayList<Child_Items> ch_list= new ArrayList<Child_Items>();
    ch = new Child_Items();
    int i=0;
    int size=1;

    for (String group_title : group_titles) {
        Group_Items gru = new Group_Items();

        gru.setName(group_title);

        ch_list = new ArrayList<Child_Items>();
        for (; i < size; i++) {
            Child_Items ch = new Child_Items();

            ch.setChild_title(child_info[i]);
            ch.setDd("Due Date:");
            ch.setDate(dates[i]);

            ch_list.add(ch);
        }

        gru.setItems(ch_list);
        list.add(gru);
        size=size+1;
    }
    return list;
}
  

MyCustomAdapter(MyBaseExpandableListAdapter)

@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));

    return convertView;
}

2 个答案:

答案 0 :(得分:1)

在getview()函数中放入一个简单的条件

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);
    if(groupPosition==7)
       ch.setVisibility(View.GONE);
    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));
        }
    });
}

答案 1 :(得分:0)

  

我发现以下解决方案是代码

@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) {
    chk.setVisibility(View.GONE);
    return convertView;
}
else {
    chk.setVisibility(View.VISIBLE);
    return convertView;
}