title: how to save the state of my CheckBox items in ListView with BaseAdapter
body: <p>My CourseFragmentActivity class  extends FragmentActivity that uses a ViewPager with 5 tabs. I have a ListView in each tab that displays an ArrayList of CheckBox items. On the 5th tab of my ViewPager, I have a single button to navigate to another FragmentActivity class. The problem is when I select a CheckBox item in one of my ListView in CourseFragmentActivity class, then I click on the button to navigate to another FragmentActivity class, I lose the state of the CheckBox item when I navigate back to my CourseFragmentActivity class from the other FragmentActivity class. How do I save the state of my CheckBox items in ListView when switching between 2 FragmentActivity through my BaseAdapter?</p>
  
  <p>Below is my BaseAdapter for setting the CheckBox items of my ListView:</p>
  
  <pre><code>package com.usjr.sss.adapter;
  
  import java.util.ArrayList;
  import com.usjr.sss.MyConstants;
  import com.usjr.sss.R;
  import com.usjr.sss.activity.CourseFragmentActivity;
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.CheckBox;
  import android.widget.CompoundButton;
  import android.widget.CompoundButton.OnCheckedChangeListener;
  
  public class InfoTechAdapter extends BaseAdapter {
  
  private ArrayList&lt;String&gt; subjectArrayList;
  private CourseFragmentActivity activity;
  private String subject;
  
  public InfoTechAdapter(CourseFragmentActivity activity,
          ArrayList&lt;String&gt; subjectArrayList) {
      this.activity = activity;
      this.subjectArrayList = subjectArrayList;
  }
  
  @Override
  public int getCount() {
      if (subjectArrayList != null) {
          return subjectArrayList.size();
      } else {
          return 0;
      }
  }
  
  @Override
  public String getItem(int position) {
      if (subjectArrayList != null) {
          return subjectArrayList.get(position);
      } else {
          return null;
      }
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
  
      ViewHolder viewHolder;
  
      if (convertView == null) {
          LayoutInflater inflater = (LayoutInflater) this.activity
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = inflater.inflate(R.layout.subject_row, null);
          viewHolder = new ViewHolder();
          viewHolder.checkBoxToSend = (CheckBox) convertView
                  .findViewById(R.id.subject);
          viewHolder.checkBoxToSend.setText(getItem(position));
          subject = viewHolder.checkBoxToSend.getText().toString();
          /**
           * Missing set checked state of CheckBox item
           */
  
          convertView.setTag(viewHolder);
      } else {
          viewHolder = (ViewHolder) convertView.getTag();
      }// end if-else (convertView == null)
  
      viewHolder.ref = position;
      viewHolder.checkBoxToSend.setClickable(true);
  
      viewHolder.checkBoxToSend.setOnClickListener(new MyClickListener(
              viewHolder));
      viewHolder.checkBoxToSend
              .setOnCheckedChangeListener(new MyCheckChangeListener(
                      viewHolder));
  
      return convertView;
  }// end getView
  
  class ViewHolder {
      private CheckBox checkBoxToSend;
      int ref;
  }// end ViewHolder
  
  /**
   * Handle onClick
   */
  class MyClickListener implements OnClickListener {
  
      ViewHolder viewHolder = null;
  
      public MyClickListener(ViewHolder viHolder) {
          viewHolder = viHolder;
      }
  
      @Override
      public void onClick(View v) {
          ArrayList&lt;String&gt; arrayListSelectedSubject = MyConstants.ARRAYLIST_SELECTED_SUBJECT;
          String stringNull = String.valueOf(arrayListSelectedSubject);
          String subject = ((CheckBox) v).getText().toString();
  
          if (((CheckBox) v).isChecked()) {
              /**
               * Check if ARRAYLIST_SELECTED_SUBJECT is null
               */
              if (!stringNull.equals("null")) {
                  /**
                   * if ARRAYLIST_SELECTED_SUBJECT is not null, check if
                   * ArrayList does not contain duplicate subject
                   */
                  if (!arrayListSelectedSubject.contains(subject)) {
                      arrayListSelectedSubject.add(subject);
                  }// end if
                      // (!arrayListSelectedSubject.contains(subject))
              } else {
                  /**
                   * if ARRAYLIST_SELECTED_SUBJECT is null, automatically add
                   * subject to ArrayList
                   */
                  arrayListSelectedSubject = new ArrayList&lt;String&gt;();
                  arrayListSelectedSubject.add(subject);
              }// end if-else (!stringNull.equals("null"))
          }// end if (((CheckBox) v).isChecked())
  
          if (!((CheckBox) v).isChecked()) {
              arrayListSelectedSubject.remove(arrayListSelectedSubject
                      .indexOf(subject));
          }// end if (!((CheckBox) v).isChecked())
  
          MyConstants.ARRAYLIST_SELECTED_SUBJECT = arrayListSelectedSubject;
          Log.i("ARRAYLIST_SELECTED_SUBJECT",
                  String.valueOf(MyConstants.ARRAYLIST_SELECTED_SUBJECT));
  
      }// end onClick
  }// end MyClickListener
  
  /**
   * Handle CheckBox state
   */
  class MyCheckChangeListener implements OnCheckedChangeListener {
  
      ViewHolder viewHolder = null;
  
      public MyCheckChangeListener(ViewHolder viHolder) {
          viewHolder = viHolder;
      }
  
      @Override
      public void onCheckedChanged(CompoundButton buttonView,
              boolean isChecked) {
  
          if (viewHolder.checkBoxToSend.equals(buttonView)) {
              if (!isChecked) {
                  /**
                   * Missing syntax for saving false state of CheckBox
                   */
                  Log.i("onCheckedChanged", "false");
              } else {
                  /**
                   * Missing syntax for saving true state of CheckBox
                   */
                  Log.i("onCheckedChanged", "true");
              }// end if-else (!isChecked)
  
          }// end if (viewHolder.checkBoxToSend.equals(buttonView))
  
      }// end onCheckedChanged
  }// end OncheckchangeListner
  }
  </code></pre>