Ashwani
Ashwani

Reputation: 1584

CheckBox in ListView setonclicklistener not working properly

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.

Upvotes: 0

Views: 1746

Answers (1)

mini
mini

Reputation: 855

you may use

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

    }
});

Upvotes: 1

Related Questions