I have the below code:
if(cb.isChecked())
{
selectedPlanets.add(planet.getDisplayName());
}
if (!cb.isChecked())
{
selectedPlanets.remove(planet.getDisplayName());
}
testing();
}
private void testing() {
serverString.setText(null);
Iterator<String>i = selectedPlanets.iterator();
while(i.hasNext()){
String aNum1 = i.next();
serverString.append(aNum1+",");
}
I then need to iterate through selectedPlanets but the removed ones show up too. By setting the TextView null again, it works if three or more are selected. However, if two are selected, the checked planet also gets removed from the list.
EDIT: for anyone who runs into this problem, I solved it by using the else (programmer’s block made me lose sense!) and then implementing some other methods that I needed to make it work.
Why not do this: