Switch button changing state when scrolling in listview
<p>I'm a beginner in Android development. This problem happens when I am vertically scrolling in this listview. Switch button changes the state automatically. How do I solve this issue? The code is shown below:</p>

<pre><code>public class TrainerSessionAdapterView extends BaseAdapter {
public TrainerSessionAdapterView(Context context) {
    this.context = context;
    inflater = LayoutInflater.from(this.context);
    workoutList = new ArrayList&lt;&gt;();
    newSessionList = new ArrayList&lt;&gt;();
    type = context.getResources().getString(R.string.type);
    other = context.getResources().getString(R.string.other);
    objectID = context.getResources().getString(R.string.object_id);
}

   @Override
    public int getCount() {
    if (workoutList.isEmpty()) {
        return 0;
    } else {
        return workoutList.size();
    }

}


@Override
public ParseObject getItem(int position) {
    return workoutList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    removeSession = new ArrayList&lt;String&gt;();
    trainerWorkoutList =  (ArrayList&lt;String&gt;)user.get("trainer_workout_type");
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.session_listview, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    if (!workoutList.isEmpty() &amp;&amp; position &lt; workoutList.size() &amp;&amp; change)  {
            ParseObject workoutObject = workoutList.get(position);
            if (!TextUtils.isEmpty(workoutObject.get(type).toString()));
            holder.sessionTypeView.setText(workoutObject.get(type).toString());
            if(trainerWorkoutList!=null &amp;&amp; workoutObject.getObjectId()!=null){
                if (trainerWorkoutList.contains(workoutObject.getObjectId())){
                    holder.sessionSwitch.setChecked(true);
                }
            }
            else{
                holder.sessionSwitch.setChecked(false);
            }
        }  
    return convertView;
}
}
</code></pre>