0

I have a ListView with CheckBox and a TextView . In my adapters getView() method I implemented this listener on checkbox.

holder.check.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            HashMap<String, String> localMap = (HashMap<String, String>) holder.check
                    .getTag();
            if (holder.check.isChecked()) {
                trackinglist.add(localMap.get("taskid"));
                checkedlist.add(localMap.get("taskid"));
            } else {
                if (trackinglist.contains(localMap.get("taskid"))) {
                    trackinglist.remove(localMap.get("taskid"));
                }
                if (alreadycheckedlist.contains(localMap.get("taskid"))) {
                    undonelist.add(localMap.get("taskid"));
                    alreadycheckedlist.remove(localMap.get("taskid"));
                } else {
                    checkedlist.remove(localMap.get("taskid"));
                }
            }

        }
    });

Now my problem is that the holder.check.isChecked() always returns false even when the CheckBox is clicked and it is checked . What might be causing this behavior ? and yes I dont want to use setoncheckchangelistener . Please Help.

Ashwani
  • 1,574
  • 14
  • 28

1 Answers1

1

you may use

holder.check.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        if ( isChecked )
        {
            // perform logic
        }

    }
});
mini
  • 855
  • 4
  • 15
  • 22
  • please read the last line of the question. This method is called every time the checked value changes . I want it to be fired only when the user clicks on the check. – Ashwani Nov 22 '12 at 09:38