que tenía el mismo problema en el desarrollo de un cliente a nagios androide, y he encontrado, es crucial que se asigna un nuevo valor al parámetro convertView tanto en el
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
y
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
métodos en su BaseExpandableListAdapter
extensión.
De lo contrario, los renderizadores padre/hijo se crearán desde el caché, y no le mostrarán las cosas correctas.
Necesito la casilla de verificación para mostrar si el usuario necesita algún tipo de alerta si algo va mal con el servicio observado.
Aquí es mi manera de conseguir esto:
//hosts: the list of data used to build up the hierarchy shown by this adapter's parent list.
private class MyExpandableListAdapter extends BaseExpandableListAdapter
{
private LayoutInflater inflater;
public MyExpandableListAdapter()
{
inflater = LayoutInflater.from(Binding.this);
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
final Host host = hosts.get(groupPosition);
final boolean needsLargeView = isExpanded && (host.getTitle() != null) && (host.getTitle().length() > 0);
if (needsLargeView)
convertView = inflater.inflate(R.layout.grouprow_expanded, parent, false);
else
convertView = inflater.inflate(R.layout.grouprow, parent, false);
convertView.setBackgroundResource(host.getBackgroundResource(isExpanded));
[...]
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
final Host host = hosts.get(groupPosition);
final NagService service = host.getServices().get(childPosition);
convertView = inflater.inflate(R.layout.childrow, parent, false);
convertView.setBackgroundResource(host.getChildBackgroundResource());
convertView.findViewById(R.id.servicename_status).setBackgroundResource(service.getStatusBackground());
[...]
CheckBox alertChb = (CheckBox) convertView.findViewById(R.id.alert);
alertChb.setChecked(service.isNeedsAlert());
alertChb.setOnCheckedChangeListener(new YourCheckChangedListener(service));
return convertView;
}
@Override
public Object getChild(int groupPosition, int childPosition)
{
return hosts.get(groupPosition).getServices().get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
@Override
public int getChildrenCount(int groupPosition)
{
return hosts.get(groupPosition).getServices().size();
}
@Override
public Object getGroup(int groupPosition)
{
return hosts.get(groupPosition);
}
@Override
public int getGroupCount()
{
return hosts.size();
}
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public void notifyDataSetChanged()
{
super.notifyDataSetChanged();
}
@Override
public boolean isEmpty()
{
return ((hosts == null) || hosts.isEmpty());
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return true;
}
@Override
public boolean hasStableIds()
{
return true;
}
@Override
public boolean areAllItemsEnabled()
{
return true;
}
}
El childrow.xml entre los diseños utilizados es el que contiene la casilla de verificación.
Dentro del CheckedChanhedListener
debe guardar el nuevo estado en la instancia afectada (en mi caso, el servicio).
espero que esto le ayuda
Gracias Rakesh, parece un buen tutorial, pero parece tratar sólo con listviews, en las que a mí más intereseted en ExpandableListViews .. –