ExpandableListView Android avec Case à cocher, Contrôle de l'état vérifié

Amis,

Je suis en train d'écrire une application qui utilisent la case à cocher dans ExpandableListView, j'ai un problème, là, qui est le maintien de la case de l'état de l'application, j'ai eu l'exemple de ici , mon problème est le maintien de l'état coché les cases à cocher, à chaque fois que j'ai cocher l'une des cases à cocher et d'Élargir la Liste, les cases n'ont pas l'objet d'etat où ils sont censés avoir. J'ai essayer de maintenir par l'ajout de liste de tableaux pour stocker la position de la stocker et recharger la position dans getChildView (), mais toujours pas à réaliser ce que je veux faire. voici mon code

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;
}
}

source d'informationauteur NyanLH