title: Android get text of all checked checkboxes in listView
body: <p>hello i have created a listview with checkboxes in it...
  but i dont know how to get the check box text which are selected.. here is the code of activity_main.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/LinearLayout1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:gravity="top"
      android:orientation="vertical"
      tools:context=".MygamesActivity" &gt;
  
      &lt;ListView
          android:id="@android:id/list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_marginTop="20dp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>another layout which has checkboxes to show in the listview main.list_item.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;CheckBox
          android:id="@+id/checkBox1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="CheckBox"
           /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and this is the class that extends arrayadapter</p>
  
  <pre><code>package com.wasiff.listview;
  
  import android.content.Context;
  import android.content.res.TypedArray;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.CheckBox;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  
  public class CheckboxAdapter extends ArrayAdapter&lt;String&gt; {
      private LayoutInflater mInflater;
  
      private String[] mStrings;
      private TypedArray mIcons;
      private int mViewResourceId;
  
      public CheckboxAdapter(Context ctx,int viewResourceId,String[] strings){
          super(ctx,viewResourceId,strings);
  
          mInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          mStrings = strings;
  
          mViewResourceId = viewResourceId;
      }
  
      public int getCount(){
          return mStrings.length;
      }
  
      public String getItem(int position){
          return mStrings[position];
      }
  
      public long getItemId(int position){
          return 0;
      }
  
      public View getView(int position,View convertView,ViewGroup parent){
          convertView = mInflater.inflate(mViewResourceId, null);
  
          CheckBox tv = (CheckBox)convertView.findViewById(R.id.checkBox1);
          tv.setText(mStrings[position]);
  
          return convertView;
      }
  }
  </code></pre>
  
  <p>and this is my mainActivity class</p>
  
  <pre><code>package com.wasiff.listview;
  
  import android.app.ListActivity;
  import android.content.Context;
  import android.content.res.Resources;
  import android.content.res.TypedArray;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.View;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.Button;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  
  public class MainActivity extends ListActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Context ctx = getApplicationContext();
          Resources res = ctx.getResources();
  
          String[] options = res.getStringArray(R.array.countrynames);
  
          setListAdapter((ListAdapter) new CheckboxAdapter(ctx,R.layout.main_list_item,options));
  
      }
  
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>and finally i have all the countries saved in a countries.xml file on values folder</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;string-array name="countrynames" translatable="false"&gt;
          &lt;item&gt;Bhutan&lt;/item&gt;
          &lt;item&gt;Colombia&lt;/item&gt;
          &lt;item&gt;India&lt;/item&gt;
          &lt;item&gt;Pakistan&lt;/item&gt;
          &lt;item&gt;Australia&lt;/item&gt;
          &lt;item&gt;Srilanka&lt;/item&gt;
          &lt;item&gt;England&lt;/item&gt;
      &lt;/string-array&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>it shows the check boxes in the listView now what i want is to get the text of the checkboxes which are checked and show in a toast on a button click(to test) i followed the tutorial on android cookbook by oreilly but still i dont know how to set the listener</p>