title: RadioButton change state during listview scolling
body: <p>I have a ListView, which has a TextView and a RadioGroup with 2 RadioButtons as Children in each row. Now i can select a RadioButton in each row. But if i scroll the ListView, my Selection is gone or it does not show correctly. For example, i choose the RadioButton A in the first row, if i scroll the ListView and then go back to the first row again B is checked instead of A. How can i fix this Problem? Can anybody help me? I'll be very appriciate of that.</p>
  
  <pre><code>package com.rextart.org.mico.view.adapter;
  
  import java.sql.SQLException;
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.CompoundButton;
  import android.widget.CompoundButton.OnCheckedChangeListener;
  import android.widget.ImageButton;
  import android.widget.RadioButton;
  import android.widget.TextView;
  
  import com.rextart.org.mico.R;
  import com.rextart.org.mico.dao.entity.TabNonConf;
  import com.rextart.org.mico.dao.entity.TabSopralluoghi;
  import com.rextart.org.mico.dao.service.TabNonConfService;
  import com.rextart.org.mico.dao.service.TabSopralluoghiService;
  import com.rextart.org.mico.utils.StoreForArrTabNonConf;
  
  public class ListaNonConformitaAdapter extends ArrayAdapter&lt;TabNonConf&gt; {
  
      private ArrayList&lt;TabNonConf&gt; arrNonConf;
      private LayoutInflater mInflater;
  private Context context;
  private boolean visible;
  private TabSopralluoghi objSop;
  protected ViewHolder holder;
  
  public ListaNonConformitaAdapter(Context context, TabSopralluoghi objSop, int resource, ArrayList&lt;TabNonConf&gt; arrNonConf,boolean visible) {
      super(context, resource, arrNonConf);
      this.context = context;
      this.arrNonConf = arrNonConf;
      this.visible = visible;
      this.objSop = objSop;
  }
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      final TabNonConf tab = arrNonConf.get(position);
      if (convertView == null){
          mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = mInflater.inflate(R.layout.adapter_item_non_conformita, null);
      }
      holder = new ViewHolder();
      holder.conforme = (RadioButton)convertView.findViewById(R.id.conf_si);
      holder.nonConforme = (RadioButton)convertView.findViewById(R.id.conf_no);
      holder.nomeNonConf = (TextView)convertView.findViewById(R.id.nome_non_conformita);
      holder.indice = (TextView)convertView.findViewById(R.id.numero_non_conformita);
      holder.elimina = (ImageButton)convertView.findViewById(R.id.elimina_non_conf);
  
      setclickableCheck(holder);
  
      if(visible){
          holder.elimina.setVisibility(View.VISIBLE);
      }else{
          holder.elimina.setVisibility(View.INVISIBLE);
      }
  
      if(tab.getDescNonConf().length()&gt;25){
          holder.nomeNonConf.setText(tab.getDescNonConf().substring(0, 25)+" ...");
      }else{
          holder.nomeNonConf.setText(tab.getDescNonConf());
      }
  
      int posizione = position+1;
      holder.indice.setText(saveString(""+posizione));
  
      if(tab.getFlagOk()==1){
          holder.conforme.setChecked(true);
          holder.nonConforme.setChecked(false);
      }else{
          holder.conforme.setChecked(false);
          holder.nonConforme.setChecked(true);
      }
  
      holder.conforme.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if(isChecked){
                  tab.setFlagOk(1);
              }else{
                  tab.setFlagOk(0);
              }
              StoreForArrTabNonConf.getInstance().add(tab);
          }
      });
  
      holder.elimina.setOnClickListener(new OnClickListener() {
  
          public void onClick(View v) {
              AlertDialog.Builder alert = new AlertDialog.Builder((Activity)context);
              alert.setTitle("");
              alert.setCancelable(true);
              alert.setMessage(R.string.eliminazione);
              alert.setPositiveButton(R.string.label_ok,new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {                   
                      try {
                          TabNonConfService objConfService = new TabNonConfService(((Activity)context).getApplication());
                          objConfService.delete(tab);
                          ArrayList&lt;TabNonConf&gt; arr = objConfService.getList(""+objSop.getId());
                          if(arr.isEmpty()){
                              TabSopralluoghiService objService = new TabSopralluoghiService(((Activity)context).getApplication());
                              objService.delete(objSop);
                          }
                          ListaNonConformitaAdapter.this.remove(ListaNonConformitaAdapter.this.getItem(position));
                          notifyDataSetChanged();
                      } catch (SQLException e) {}
                  }
              });
              alert.setNegativeButton(R.string.label_annulla,new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {                   
                      dialog.cancel();
                  }
              });
              alert.show();
          }
      });
  
      return convertView;
  }
  
  /**
   * @description method to set if the radiobuttons are clickable or not
   * @param holder
   */
  protected void setclickableCheck(ViewHolder holder) {
      holder.conforme.setClickable(true);
      holder.nonConforme.setClickable(true);
  }
  
  /**
   * @description method to return the value of a object's field or an empty string
   * @param field
   * @return field from the object or space
   */
  private String saveString(String field){
      if (field == null) 
          return "";
      else 
          return field;
  }
  
  static class ViewHolder{
      RadioButton conforme;
      RadioButton nonConforme;
      TextView nomeNonConf;
      TextView indice;
      ImageButton elimina;
  }
  </code></pre>
  
  <p>}</p>