setOnCheckedChangeListener is getting invoked everytime the view is built
<p>I have a class <code>Devices</code> that stores the checked state of the Switch using <code>setChecked(boolean)</code> and gets it by the <code>isChecked()</code> method.</p>

<p>Using this, I'm saving the state of the switch once once it is toggled.</p>

<p>But, if I change the state of a switch to ON, every time I scroll down and up back to the switch, <code>setOnCheckedChangeListener</code> is invoked. How do I prevent this?</p>

<pre><code>    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View row = convertView;
        DeviceHolder holder = null;
        Devices devices = list.get(position);
        String id = devices.id;

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new DeviceHolder();
        holder.devTxt = (TextView) row.findViewById(R.id.devdesc);
        holder.nameTxt = (TextView) row.findViewById(R.id.devname);
        holder.toggleSwitch = (Switch) row.findViewById(R.id.toggleswitch);
        holder.txt = (TextView) row.findViewById(R.id.debug);
        final int i=id;

        final Switch tswitch = holder.toggleSwitch;
        holder.toggleSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                      //Comes here every time I scroll to a button that is ON
                        Control._service.write(i);
                        list.get(position).setChecked(tswitch.isChecked());
                    }
                });

        holder.devTxt.setText(devices.dev);
        holder.nameTxt.setText(devices.name);
        holder.txt.setText(id);
        if (tswitch.isChecked() != devices.isChecked())
            holder.toggleSwitch.setChecked(devices.isChecked());

        return row;
    }
</code></pre>
