Android ExpandableListView con casilla de verificación, Control de estado verificado
Amigos
Estoy tratando de escribir una aplicación que use la casilla de verificación en ExpandableListView, tengo un problema aquí que es mantener el estado de la casilla de verificación de la aplicación, obtuve el ejemplo deaqu, mi problema es mantener el estado marcado de las casillas de verificación, siempre que marque una de las casillas de verificación y Expanda la Lista, las casillas de verificación no tienen el estado marcado donde se suponía que debían estar. He tratado de mantener agregando ArrayList para almacenar la posición de la tienda y volver a cargar la posición en getChildView () pero aún así no lograr lo que quiero hacer. aquí está mi código
public class ElistCBox extends ExpandableListActivity {
private static final String LOG_TAG = "ElistCBox";
ArrayList<String > chkState = new ArrayList<String>();
static final String colors[] = {"grey","blue","yellow","red"};
static final String shades[][] ={ { "lightgrey","#D3D3D3","dimgray","#696969", "sgi >gray 92","#EAEAEA"},
{ "dodgerblue 2","#1C86EE","steelblue >2","#5CACEE","powderblue","#B0E0E6"},
{ "yellow 1","#FFFF00", "gold 1","#FFD700","darkgoldenrod 1"," #FFB90F" },
{"indianred 1","#FF6A6A", "firebrick 1","#FF3030", "maroon","#800000" } };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
this,
createGroupList(),
R.layout.group_row, new String[] { "colorName" },
new int[] { R.id.childname }, createChildList(),
R.layout.child_row,
new String[] { "shadeName", "rgb" },
new int[] { R.id.childname, R.id.rgb }
) {
@Override public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final CheckBox chkColor = (CheckBox)v.findViewById(R.id.check1);
if(chkState.contains(groupPosition+","+childPosition)){
chkColor.setChecked(true);
}else{
chkColor.setChecked(false);
}
chkColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.e("Checkbox Onclick Listener", Integer.toString(groupPosition) + " - " + Integer.toString(childPosition));
}
});
chkColor.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.e("Checkbox check change Listener", Integer.toString(groupPosition) + " - " + Integer.toString(childPosition));
if(chkColor.isChecked()){
chkState.add(groupPosition+","+childPosition);
} else {
chkState.remove(groupPosition+","+childPosition);
}
}
});
return super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
}
};
setListAdapter( expListAdapter );
}
public void onContentChanged () {
super.onContentChanged();
Log.e( LOG_TAG, "onContentChanged" );
}
public boolean onChildClick(
ExpandableListView parent,
View v,
int groupPosition,
int childPosition,
long id) {
Log.e( LOG_TAG, "onChildClick: "+childPosition );
CheckBox cb = (CheckBox)v.findViewById( R.id.check1 );
if( cb != null )
cb.toggle();
return false;
}
public void onGroupExpand (int groupPosition) {
Log.e( LOG_TAG,"onGroupExpand: "+groupPosition );
}
private List createGroupList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < colors.length ; ++i ) {
HashMap m = new HashMap();
m.put( "colorName",colors[i] );
result.add( m );
}
return (List)result;
}
private List createChildList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < shades.length ; ++i ) {
ArrayList secList = new ArrayList();
for( int n = 0 ; n < shades[i].length; n += 2 ) {
HashMap child = new HashMap();
child.put( "shadeName", shades[i][n] );
child.put( "rgb", shades[i][n+1] ); secList.add( child );
}
result.add( secList );
}
return result;
}
}