Vista de lista de Android con casillas de verificación que no se comportan como se espera

Esto es con respecto al tema del reciclaje. Estoy usando un adaptador personalizado para rellenar la vista de lista. En la fila personalizada hay una vista de imagen, dos cuadros de texto y una casilla de verificación. Todos los elementos se rellenan, pero la casilla de verificación no se rellena correctamente.

Dentro degetView() Realizo una condición y si la condición es verdadera, establezco la casilla de verificación para habilitar el estado. Esto funciona bien pero con la casilla de verificación correcta que está marcada, también hay otras casillas de verificación marcadas. Pasé por muchas preguntas similares de desbordamiento de pila pero no pude encontrar una respuesta. Cualquier ayuda es muy apreciada.

A continuación se muestra mi clase de adaptador:

public class LocationsListAdapter extends BaseAdapter {

    List<Locations> data;
    Context context;
    Locations userSelectedLocation;
    private SharedPreferences locationPreferences;
    private SharedPreferences.Editor locationPrefsEditor;

    public LocationsListAdapter(List<Locations> data, Context c) {
        this.data = data;
        this.context = c;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @SuppressWarnings("static-access")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


        ViewHolder holder = null;
        Log.v("ConvertView", String.valueOf(position));

        if (convertView == null) {
            LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(R.layout.find_your_location_row, null);

            holder = new ViewHolder();
            holder.LocationImage = (SmartImageView) convertView.findViewById(R.id.loca_row_image);
            holder.locationName = (TextView) convertView.findViewById(R.id.txt_loca_name);
            holder.LocationDescription = (TextView) convertView.findViewById(R.id.txt_loca_desc);
            holder.locationCheckText = (TextView) convertView.findViewById(R.id.txt_check);
            holder.locationCheck = (CheckBox) convertView.findViewById(R.id.location_check);
            holder.locationCheck.setOnCheckedChangeListener(myCheckChangList);
            convertView.setTag(holder);

            locationPreferences = context.getSharedPreferences("locationPrefs", context.MODE_PRIVATE);
            locationPrefsEditor = locationPreferences.edit();
            String locationID  = locationPreferences.getString("locationID", "");

            try {
                if(locationID.contains(String.valueOf(data.get(position).getLocationID()))){
                    holder.locationCheck.setChecked(true);
                }
            } catch (Exception e) {
                Log.e("Fatal", " Exception");
            }


             holder.locationCheck.setOnClickListener( new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        userSelectedLocation = data.get(position);
                        locationPreferences = context.getSharedPreferences("locationPrefs", context.MODE_PRIVATE);
                        locationPrefsEditor = locationPreferences.edit();
                        String userSelectedLocationID = userSelectedLocation.getLocationID();
                        locationPrefsEditor.clear();
                        locationPrefsEditor.putString("locationID", userSelectedLocationID);
                        locationPrefsEditor.commit();
                        Intent intent = new Intent(context, HomeScreen.class);
                        context.startActivity(intent);
                        Log.e("Check Box ", "Clicked");
                    }
            });

        }else {
            holder = (ViewHolder) convertView.getTag();
           }

        final Locations location = data.get(position);

        holder.LocationImage.setImageUrl(location.getImagePath());
        holder.locationName.setText(location.getLocationName());
        holder.LocationDescription.setText(location.getLocationDescription());

        return convertView;
    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver observer) {
        if (observer != null) {
            super.unregisterDataSetObserver(observer);
        }
    }

    protected class ViewHolder {
        protected SmartImageView LocationImage;
        protected TextView locationName;
        protected TextView LocationDescription;
        protected TextView locationCheckText;
        protected CheckBox locationCheck ;
    }

    OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            Log.e("checked", "");
        }
    };
}

Respuestas a la pregunta(6)

Su respuesta a la pregunta