lundi 5 octobre 2015

IndexOutOfBoundsException in a ListView with checkbox

I've placed a checkbox in a custom array adapter of an listview. The adapter works fine when I check the checkbox. But when I try to uncheck the checkbox in a random manner the application throws.

Here's my code for your reference:

holder1.chckbx1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
        if (isChecked) {
            Log.i("checked", "checked");
            positionArray.set(position, true);
            broadCastDetailsLists.add(new BroadCastDetailsList(cpsId2, cpsType2, position, cpsName,handShakeStatus, favouriteStatus));

            sendEnquiry.add(new Q2_SendEnquiryList(searchresultList.get(position).getCpsId(), searchresultList.get(position).getCpsName()));

        } else {
            Log.i("unchecked", "unchecked");
            positionArray.set(position, false);
            broadCastDetailsLists.remove(position);
            sendEnquiry.remove(position);
        }
    }
});

Also here's my log for your reference




Aucun commentaire:

Enregistrer un commentaire