title: Pass the checked status of CheckBoxes from rows of a ListView to another Activity on a Button click
body: <p><strong>Problem</strong>: After I checked multiple <code>CheckBoxes</code> that are displayed in a custom <code>ListView</code>, I still get back the whole row of data values shown in the custom <code>ListView</code> regardless of the selections I made. I guess the <code>CheckBox</code>'s status never changed at all after I checked them. So how to set the <code>CheckBox</code> status(true) after I checked multiple <code>CheckBoxes</code>? Furthermore, how to get the checked <code>CheckBoxes</code> positions from the <code>ListView</code> when I click a submit <code>Button</code>? Then, how to call <code>Model</code>'s class to retrieve the specific row of data including the <code>TextView</code> and <code>EditText</code>(for user to input) to be displayed in another custom list for checked <code>CheckBoxes</code> only?</p>
  
  <p><strong>Summary</strong>: I want to display array of row of values with <strong>checked checkbox only</strong> on another page.</p>
  
  <p>testing1.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;ScrollView
          android:id="@+id/scrollView1"
          android:layout_width="match_parent"
          android:layout_height="310dp"
          android:layout_x="0dp"
          android:layout_y="-4dp" &gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent" &gt;
  
              &lt;ListView
                  android:id="@android:id/list"
                  android:layout_width="match_parent"
                  android:layout_height="293dp" &gt;
  
              &lt;/ListView&gt;
  
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_x="113dp"
          android:layout_y="346dp"
          android:text="Button" /&gt;
  
  &lt;/AbsoluteLayout&gt;
  </code></pre>
  
  <p>testing.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;CheckBox
          android:id="@+id/checkBox1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_x="208dp"
          android:layout_y="4dp"
          android:text="CheckBox" /&gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_x="11dp"
          android:layout_y="15dp"
          android:text="TextView" /&gt;
  
      &lt;TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_x="22dp"
          android:layout_y="49dp"
          android:text="TextView" /&gt;
  
      &lt;TextView
          android:id="@+id/textView3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_x="42dp"
          android:layout_y="89dp"
          android:text="TextView" /&gt;
  
      &lt;TextView
          android:id="@+id/textView4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_x="35dp"
          android:layout_y="123dp"
          android:text="TextView" /&gt;
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_width="42dp"
          android:layout_height="wrap_content"
          android:layout_x="147dp"
          android:layout_y="13dp"
          android:ems="10"
          android:inputType="number" /&gt;
  
  &lt;/AbsoluteLayout&gt;
  </code></pre>
  
  <p>MultipleSet1.java Class:</p>
  
  <pre><code>public class MultipleSet1 extends ListActivity
  {
  
  
      List&lt;Model&gt; list = new ArrayList&lt;Model&gt;();
  
       protected void onCreate(Bundle savedInstanceState)
       {
           super.onCreate(savedInstanceState);
           View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.testing1, null);
              this.setContentView(viewToLoad);
           //final ViewHolder viewHolder = new ViewHolder();
           String temp = "Set_A";
           String response = null;
           ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;();
           postParameters.add(new BasicNameValuePair("Name", temp));
  
              try
              {
                  response = CustomHttpClient.executeHttpPost("PhPScripts", postParameters);
              }
  
              catch (Exception e)
              {
                  // TODO Auto-generated catch block
                  Toast.makeText(getApplicationContext(), "Fail to connect to server7777777777.", 3).show();
              }
  
              int size = 0;
  
              try
              {
  
               JSONArray jArray = new JSONArray(response);
               size = jArray.length();
  
               for(int i =0; i&lt;size; i++)
               {
                  JSONObject json_data = jArray.getJSONObject(i);
                  list.add(get(json_data.getString("description"), json_data.getString("price"), false));
  
               }
  
              }
              catch (JSONException e)
              {
                 Toast.makeText(getApplicationContext(), "Fail to connect to server7777777777.", 3).show();
              }
  
               ArrayAdapter&lt;Model&gt; adapter = new InteractiveListViewAdapter(this, list);
               setListAdapter(adapter);
  
               Button button1 = (Button) findViewById(R.id.button1);
               button1.setOnClickListener(new View.OnClickListener() {
  
                      //@Override
                      public void onClick(View v) {
  
                          ListView list = (ListView)findViewById(android.R.id.list);
                          list = getListView();
                          list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
                          int size = list.getCount();
                          String checked = "";
  
                           String unchecked = "";
                           SparseBooleanArray sparseBooleanArray = list.getCheckedItemPositions();
  
                           for(int i = 0; i &lt; size; i++)
                           {
  
                               if(sparseBooleanArray.get(i) == true) 
                               {
                                   checked += list.getItemAtPosition(i).toString() + "\n";
                               }
                               else  if(sparseBooleanArray.get(i) == false) 
                               {
                                   unchecked+= list.getItemAtPosition(i).toString() + "\n";
                               }
  
  
                           }
  
                              Intent intent = new Intent(getApplicationContext(), SingleSet.class);
                              intent.putExtra("TAG_DESCRIPTION", unchecked);
  
                              // Create the view using TabTour's LocalActivityManager
                              View view1 = bookingTab.group.getLocalActivityManager().startActivity("BookingTab", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                              .getDecorView();
  
                              // Again, replace the view
                              bookingTab.group.replaceView(view1);
  
                      }
               });
  
  
  
  
       }
  
       private Model get(String name, String score, boolean selected)
       {
           return new Model (name, score, selected);
       }
  
  }
  </code></pre>
  
  <p>InteractiveListViewAdapter.java Class:</p>
  
  <pre><code>public class InteractiveListViewAdapter extends ArrayAdapter&lt;Model&gt;
  {
      private final List&lt;Model&gt; list;
      private final Activity context;
  
      public InteractiveListViewAdapter(Activity context, List&lt;Model&gt; list) 
      {
          super(context, R.layout.testing, list);
          this.context = context;     
          this.list = list;   
      }
  
      static class ViewHolder
      {        
          protected TextView text; 
          protected CheckBox checkbox;        
          protected EditText scores;     
      }
  
      //@Override     
      public View getView(int position, View convertView, ViewGroup parent)
      {        
          View view = null;
  
          if (convertView == null)
          {             
              LayoutInflater inflator = context.getLayoutInflater(); 
  
              view = inflator.inflate(R.layout.testing, null); 
  
              final ViewHolder viewHolder = new ViewHolder(); 
              viewHolder.text = (TextView) view.findViewById(R.id.textView1);
              viewHolder.scores=(EditText) view.findViewById(R.id.editText1);
              viewHolder.scores.addTextChangedListener(new TextWatcher()
              {  
                  public void onTextChanged(CharSequence s, int start, int before, int count)
                  {      
                      Model element=(Model)viewHolder.scores.getTag();
                      element.setScore(s.toString());        
                  }    
  
                  public void beforeTextChanged(CharSequence s, int start, int count,int after)
                  {       
  
                  }
  
                  public void afterTextChanged(Editable s)
                  { 
  
                  }
             });         
  
              viewHolder.checkbox = (CheckBox) view.findViewById(R.id.checkBox1);      
              viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
              {
                 public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
                 {    
                     Model element = (Model) viewHolder.checkbox.getTag();  
                     element.setSelected(buttonView.isChecked());      
                 }
              }); 
  
              viewHolder.checkbox.setTag(list.get(position));
              viewHolder.scores.setTag(list.get(position));
              view.setTag(viewHolder);   
          } 
  
          else 
          {
              view = convertView; 
              ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
              ((ViewHolder) view.getTag()).scores.setTag(list.get(position)); 
          }                
  
          ViewHolder holder = (ViewHolder) view.getTag(); 
          holder.text.setText(list.get(position).getName());
          holder.scores.setText(list.get(position).getScore());    
          holder.checkbox.setChecked(list.get(position).isSelected());    
          return view;
  
      }
  
  }
  </code></pre>
  
  <p>Model.java Class:</p>
  
  <pre><code>public class Model
  {
      private String name;
      private String score;
      private boolean selected;
  
  
      public Model(String name, String score, boolean selected)
      { 
          this.name = name;
          this.score = score;
          this.selected = selected;
  
      }
  
      public String getName()
      {  
          return name;     
      }
  
      public void setName(String name)
      {    
          this.name = name;   
  
      }
  
      public boolean isSelected() 
      {     
          return selected;   
      }
  
      public void setSelected(boolean selected)
      {    
          this.selected = selected;   
      }
  
      public String getScore()
      {     
          return score;    
      }
  
      public void setScore(String score)
      { 
          this.score = score;     
      }
  }
  </code></pre>