title: How to save state of CheckBox while scrolling in ListView?
body: <p>I have used ListView with custom adapter, so my ListView includes CheckBox, but problem is that when I scroll down, checked CheckBoxes uncheck, how can I do it with this code?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My custom adapter:</p>
  
  <pre><code>    public class AppsArrayAdapter extends ArrayAdapter&lt;String&gt; {
      private final Context context;
  
      private List&lt;Integer&gt; checkedItems;
  
      private final String DefaultApps = "def_apps";
  
      public AppsArrayAdapter(Context context, String[] values, List&lt;Integer&gt; checkedItems) {//XXX
          super(context, R.layout.apps, values);
          this.context = context;
          this.checkedItems = checkedItems;//XXX
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          SharedPreferences myPrefsApps =context.getSharedPreferences("myPrefsApps", Context.MODE_PRIVATE);
          String prefNameDefaultApps = myPrefsApps.getString(DefaultApps, "");
          String prefNameDefaultAppsVer = myPrefsApps.getString(DefaultAppsVer, "");
  
  
          LayoutInflater inflater = (LayoutInflater)context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          View rowView = inflater.inflate(R.layout.apps, parent, false);
          TextView text_apps = (TextView)rowView.findViewById(R.id.text_apps);
          CheckBox check = (CheckBox)rowView.findViewById(R.id.check_apps);
          text_apps.setText(prefNameDefaultApps.split("\n")[position]);
  
          check.setChecked(checkedItems.contains((Integer) position));
          return rowView;
      }   
  }
  </code></pre>
  
  <p>And my Activity:</p>
  
  <pre><code>    public class AppsActivity extends ListActivity {
      private final String DefaultApps = "def_apps";
  
      private List&lt;Integer&gt; checkedItems = new ArrayList&lt;Integer&gt;();
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          AppsArrayAdapter adapter = new AppsArrayAdapter(this, prefNameDefaultApps.split("\n"), checkedItems);
          setListAdapter(adapter);
  }
  }
  @Override
      public void onListItemClick(ListView l, View v, int position, long id) {
         if(checkedItems.contains((Integer) position)) checkedItems.remove((Integer) position);
         else checkedItems.add((Integer) position);
      }
  </code></pre>