[Java for Android App Development] mattissimo:
i've an ExpandableListView, where i can select different radiobutton choice in a radiobuttongroup. My problem: not all radiobuttons are selected...the behaviour is random.

this is my code

void prepareMainList(String data)
{

Document doc;
NodeList nl;

newsNotificationData = new ArrayList<Map<String, String>>(); //set this struct in other case

groupData = new ArrayList<Map<String, String>>();
childData = new ArrayList<List<Map<String, String>>>();

if ((data.compareTo("") != 0) && (data != null) )
{
doc = parser.getDomElement(data); // getting DOM element

nl = doc.getElementsByTagName(KEY_GROUP);

categoryList = new HashSet<CategoryClass>();

// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++)
{
// creating new HashMap
Map<String, String> curGroupMap = new HashMap<String, String>();
Map<String, String> curNewsMap = new HashMap<String, String>();
Element el = (Element) nl.item(i);

CategoryClass myCat = new CategoryClass();
myCat.id = parser.getValue(el, "id");
myCat.name = parser.getValue(el, KEY_NAME);
myCat.subCategory = new HashSet<TournamentClass>();

// adding each child node to HashMap key => value
curGroupMap.put(CATEGORY, parser.getValue(el, KEY_NAME));
Log.d("test", "category id added: " + myCat.id);

// adding HashList to ArrayList
groupData.add(curGroupMap);

//notification
curNewsMap.put("CID_" + myCat.id, getValueFromCategory(myCat.id));
newsNotificationData.add(curNewsMap);

NodeList ls = el.getElementsByTagName("girone");

//Log.d("test", "getDataFromWebService get children count : " + ls.getLength());
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < ls.getLength(); j++)
{
Element elc = (Element) ls.item(j);
Map<String, String> curChildMap = new HashMap<String, String>();

TournamentClass myTournament = new TournamentClass();
myTournament.id = elc.getAttribute("id");
myTournament.name = parser.getValue(elc, KEY_CHILD_NAME);

curChildMap.put(TOURNAMENT, parser.getValue(elc, KEY_CHILD_NAME));

children.add(curChildMap);

myCat.subCategory.add(myTournament);

//notification
curNewsMap.put("TID_" + myTournament.id, "-1");
newsNotificationData.get(i).put("TID_" + myTournament.id, getValueFromTournament(myTournament.id));

}

childData.add(children);
categoryList.add(myCat);

//newsNotificationData.add(curNewsMap);
}

}

catList = (ExpandableListView) findViewById(R.id.expandableSettings);
catList.setClickable(true);

catList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
Log.d("test", "GROUP PRESSED");
return false;
}
});

// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
this,
groupData,
R.layout.settings_header,
new String[] { CATEGORY, TOURNAMENT },
new int[] { R.id.settingsCatTitle, android.R.id.text2 },
childData,
R.layout.settings_child,
new String[] { CATEGORY, TOURNAMENT },
new int[] { android.R.id.text1, R.id.settingsSubTitle }
){

@Override
public View getGroupView (final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
//final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
final View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);

//Log.d("test", "get tournament selected");
TextView tv = (TextView)v.findViewById( R.id.settingsCatTitle );
String catSel = tv.getText().toString();

//get objects
String groupName = groupData.get(groupPosition).get("CATEGORY");
final CategoryClass myCat = getCategoryFromName(groupName);

RadioGroup groupNN;

// *** Gestisce l'header della categoria ***
groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN);
groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//Log.d("Header chk", "id" + checkedId);
if(!isDataLoaded) return;
for (int i = 0, l = group.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) group.getChildAt(i);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(R.drawable.settings_gradient_on);
}

//-----change data to send
String notifValue = "0";

//get checked value
switch (checkedId)
{
case R.id.button_News:
notifValue = "0";
break;

case R.id.button_Notif:
notifValue = "1";
break;

case R.id.button_All:
notifValue = "2";
break;

case R.id.button_no:
notifValue = "-1";
break;

default:
break;

}

//set graphics on selected radio button
RadioButton radio = (RadioButton) v.findViewById(checkedId);
if (radio != null)
{
//radio.setTextSize(30);
// Marco Moscatelli 28/11/2013 - imposto il check a true
//radio.setChecked(true);
radio.setBackgroundResource(R.drawable.settings_gradient_on);
radio.setTextColor(Color.LTGRAY);
}

updateNewsNotificationCenter(groupPosition, myCat.id, null, notifValue);

isDataLoaded = false;

//Log.d("test", "------END SET CATEGORY------- ");

}
});
//-----data to send changed

isDataLoaded = false;
//set default schema
//String defaultbtnValue = null;
String defaultbtnValue = newsNotificationData.get(groupPosition).get("CID_" + myCat.id);
//Log.d("test", "check current cat id : "+ myCat.id);

RadioButton defNNRadio = null;
//Log.d("test", "defaultbtnValue : "+ defaultbtnValue);

if (defaultbtnValue == null)defaultbtnValue = "-1";

switch(Integer.parseInt(defaultbtnValue))
{

case 0:
defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
break;
case 1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
break;
case 2:
defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
break;
case -1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
break;

default:
break;
}

//set default button
for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
xRadio.setChecked(false);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(R.drawable.settings_gradient_on);
}

if (defNNRadio != null)
{
defNNRadio.setChecked(true);
defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
defNNRadio.setTextColor(Color.LTGRAY);

}

return v;
}

@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);

Log.d("test", "getChildView");

RadioGroup groupNN;
// *** gestisco i gironi della categoria ***
groupNN = (RadioGroup) v.findViewById(R.id.radioGroupNN_child);

//get objects
String groupName = groupData.get(groupPosition).get("CATEGORY");
final CategoryClass myCat = getCategoryFromName(groupName);

Map<String, String> childName = childData.get(groupPosition).get(childPosition);
final TournamentClass myTournament = getTournamentFromName(groupName, childName.get("TOURNAMENT"));

groupNN.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
//Log.d("Item chk", "id" + checkedId);
if(!isDataLoaded) return;
Log.d("test", "------INIT SET TOURNAMENT------- : " + myTournament.id);

for (int i = 0, l = group.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) group.getChildAt(i);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(color.SettingsTextOffColor);

}

//-----change data to send
String notifValue = "0";

//get checked value
switch (checkedId)
{
case R.id.button_News:
notifValue = "0";
break;

case R.id.button_Notif:
notifValue = "1";
break;

case R.id.button_All:
notifValue = "2";
break;

case R.id.button_no:
notifValue = "-1";
break;

default:
break;

}

//Get Tournament and keep id of it...after save notification mode in a struct and send all on POSTS
RadioButton radio = (RadioButton) v.findViewById(checkedId);
if (radio != null)
{
// Marco Moscatelli 28/11/2013 - Imposto il check a true
//radio.setChecked(true);
//group.check(radio.getId());
// end
radio.setBackgroundResource(R.drawable.settings_gradient_on);
radio.setTextColor(Color.LTGRAY);
}

//prepare data
updateNewsNotificationCenter(groupPosition, myCat.id, myTournament.id, notifValue);

Log.d("test", "------END SET TOURNAMENT------- ");
}
//}
});

//set default schema
String defaultbtnValue = newsNotificationData.get(groupPosition).get("TID_" + myTournament.id);
RadioButton defNNRadio = null;
//Log.d("test", "defaultbtnValue : "+ defaultbtnValue);

if (defaultbtnValue == null)defaultbtnValue = "-1";

switch(Integer.parseInt(defaultbtnValue))
{
case 0:
defNNRadio = (RadioButton) v.findViewById(R.id.button_News);
break;
case 1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_Notif);
break;
case 2:
defNNRadio = (RadioButton) v.findViewById(R.id.button_All);
break;

case -1:
defNNRadio = (RadioButton) v.findViewById(R.id.button_no);
break;
}

for (int i = 0, l = groupNN.getChildCount(); i < l; i++)
{
RadioButton xRadio = (RadioButton) groupNN.getChildAt(i);
xRadio.setChecked(false);
xRadio.setBackgroundResource(R.drawable.setting_gradient_off);
xRadio.setTextColor(color.SettingsTextOffColor);

}

//set default schema
if (defNNRadio != null)
{
defNNRadio.setChecked(true);
defNNRadio.setBackgroundResource(R.drawable.settings_gradient_on);
defNNRadio.setTextColor(Color.LTGRAY);
}

//isDataLoaded = true;

return v;
}

thanks in advance