How do I set a flag on when a ListItem in a ListView is checked and set it off when it is unchecked?

view story

http://stackoverflow.com – I have a ListView adapter where I am writing the ListItems from an XML. I want to flag when an item is checked and unflag it when an item is unchecked. I am using an array for storing the flag values. For Example if my ListView has four list items "Red, Blue, Green, Yellow". If Red and Green are checked, the array should be updated to [1, 0, 1, 0] and if they are unchecked it should be updated to [0, 0, 0, 0]. Below is my code. I did something wrong and it is not displaying the desired output. Can someone look into it and suggest me a better way to solve it. Thank you! ArrayAdapter<String& (HowTos)