【问题标题】:I hide the checkbox from the ExpandableListView but expandableListview doesn't work properly我从 ExpandableListView 隐藏了复选框,但 expandableListview 无法正常工作
【发布时间】:2016-02-11 09:57:21
【问题描述】:

我使用以下getView 方法创建了ExpandableListView

@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) 方法从ExpandablelistView 隐藏第三项的CheckBox 但是..

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

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

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

【问题讨论】:

  • 您必须在代码中处理 else 条件 if(groupPosition==2) { ch.setVisibility(View.GONE); } 返回转换视图; }else{ { ch.setVisibility(View.VISIBILE); } 返回转换视图; }
  • 我会检查你的答案

标签: android checkbox expandablelistview


【解决方案1】:

伙计们,我尝试了以下对我有用的答案

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2017-04-04
    相关资源
    最近更新 更多