我使用以下
创建了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
,但是......
当我展开
First
或Second
时,我面临另一个问题,然后CheckBoxes
位置会自动更改
所以我现在很困惑如何处理这个错误
Here is my app 你可以查一下,请帮帮我
答案 0 :(得分:0)
伙计们,我在这里尝试了以下答案:
if(groupPosition==2) {
chk.setVisibility(View.GONE);
return convertView;
}
else {
chk.setVisibility(View.VISIBLE);
return convertView;
}