OK this is driving me nuts. I was hoping to learn how to do this by today. Here is what I have. This is a Multi choice ListView obviously. You click the the Selection it selects, you unclick the selection it de selects. It ALMOST works perfectly. There is only one problem. It only works when 1 item is already selected. If an item is selected, Items can be selected and de selected NP. But if nothing is selected, the last one stays selected. How to I fix that?
public void onItemClick(AdapterView<?> adapterView, View view, int Position, long l) {
int cntChoice = listview.getCount();
SparseBooleanArray sparseBooleanArray = listview.getCheckedItemPositions();
for (int i = 0; i < cntChoice; i++) {
if(sparseBooleanArray.get(i)) {
switch (Position) {
case 0:
if (listview.isItemChecked(0)) {
A = "";
A = "T";
} else if (!listview.isItemChecked(0)) {A = ""; A = "F";}
break;
case 1:
if (listview.isItemChecked(1)) {
B = "";
B = "T";
} else (listview.isItemChecked(1)) {B = ""; B = "F";}
break;
case 2:
if (listview.isItemChecked(2)) {
C = "";
C = "T";
} else (listview.isItemChecked(2)) {C = ""; C = "F";}
break;
}
Toast.makeText(Billing.this, "data" + A + ", " + B + ", " + C, Toast.LENGTH_LONG).show();
}