title: Getting the text of selected checkbox from listview in android?
body: <p>I am having a List view with checkBox .I want to get all the text of selected check Box from the list view .Since ,I am new to android I refer some links which uses view holder but i am not using .</p>
  
  <pre><code>public class EcConferenceNumber extends Activity{
      ListView checkBoxNumberListView;
      ConferenceAdapter adapter;
      Button doneBtn,cancelBtn;
      EditText profileName;
      CheckBoxListViewAdapter cbAdapter;
      static ArrayList&lt;String&gt; checkBoxData = null;
      String[]  myStrings;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.ec_number_selection);   
          adapter = new ConferenceAdapter(this);
          checkBoxNumberListView = (ListView) findViewById(R.id.numberselectionlistView);
  
          doneBtn=(Button) findViewById(R.id.donenumberbutton);
          cancelBtn=(Button) findViewById(R.id.cancelnumberbutton);
          Intent intent = getIntent();
          myStrings = intent.getStringArrayExtra("strings");
      /*ArrayList&lt;String&gt; got=    cbAdapter.getSelectedString();
  
      System.out.println(""+got);*/
  
           checkBoxData=new ArrayList&lt;String&gt;(Arrays.asList(myStrings));
  
          //checkBoxNumberListView.setAdapter(new CheckBoxListViewAdapter(EcConferenceNumber.this, adapter, checkBoxData));
  
          //System.out.println(""+checkBoxData);
            final CheckBoxListViewAdapter checkBoxListViewAdapter = new CheckBoxListViewAdapter(
                      EcConferenceNumber.this, adapter, checkBoxData);
                      checkBoxListViewAdapter.setSelectedString(new ArrayList&lt;String&gt;());
                      checkBoxNumberListView.setAdapter(checkBoxListViewAdapter);
  
              doneBtn.setOnClickListener(new OnClickListener() {
  
                  @Override
                  public void onClick(View arg0) {
                      // TODO Auto-generated method stub
                      ArrayList&lt;String&gt;   a=    checkBoxListViewAdapter.getSelectedString();
                      for(String b:a)
                      System.out.println("hi hi" +b);
                  }
              });     
  
  
      }
      }
  
  class CheckBoxListViewAdapter extends BaseAdapter {
      private List&lt;String&gt; calendars = null;
  
      ArrayList&lt;String&gt; selectedString;
      public ArrayList&lt;String&gt; getSelectedString() {
          return selectedString;
      }
  
      public void setSelectedString(ArrayList&lt;String&gt; selectedString) {
          this.selectedString = selectedString;
      }
  
      LayoutInflater inflater = null;
  
      public CheckBoxListViewAdapter(Activity activity, ConferenceAdapter adapter, ArrayList&lt;String&gt; checkBoxData) {
          this.calendars = checkBoxData;
  
          inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      @Override
      public int getCount() {
          return calendars.size();
      }
  
      @Override
      public Object getItem(int position) {
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  final Context c = null;
  
          View vi = convertView;
          if (convertView == null)
              vi = inflater.inflate(R.layout.ec_checkbox_number, null);
  
          TextView cbTV = (TextView) vi.findViewById(R.id.checkboxtextView);
          final CheckBox checkBox = (CheckBox) vi.findViewById(R.id.checkBox);
  
          cbTV.setText(calendars.get(position));
  
  
          checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  if (isChecked) {
                      selectedString.add(checkBox.getText().toString());
                  }else{
                      selectedString.remove(checkBox.getText().toString());
                  }
  
  
              }
  
          });
  
          return vi;
      }
  
  
  }
  </code></pre>
  
  <p>I am getting error while selecting the checkbox .I want to store all the selected check box text.</p>
  
  <p>ec_number_selection.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/meetingprofilename"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginTop="20dp"
          android:text="Profile Name:"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/meetingprofilename"
          android:layout_alignBottom="@+id/meetingprofilename"
          android:layout_alignParentRight="true"
          android:layout_toRightOf="@+id/meetingprofilename"
          android:ems="10" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
      &lt;Button
          android:id="@+id/cancelnumberbutton"
          android:layout_width="158dp"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_alignRight="@+id/editText2"
          android:text="Cancel" /&gt;
  
      &lt;Button
          android:id="@+id/donenumberbutton"
          android:layout_width="158dp"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentRight="true"
          android:layout_toRightOf="@+id/cancelnumberbutton"
          android:text="Done" /&gt;
  
      &lt;ListView
          android:id="@+id/numberselectionlistView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_above="@+id/cancelnumberbutton"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/editText1" &gt;
  
      &lt;/ListView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>ec_checkBox_number.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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/checkBox"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_marginTop="26dp"
          android:text="" /&gt;
  
      &lt;TextView
          android:id="@+id/checkboxtextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/checkBox"
          android:layout_alignBottom="@+id/checkBox"
          android:layout_alignParentLeft="true"
          android:layout_marginLeft="107dp"
          android:text="TextView" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>error log</p>
  
  <pre><code>10-22 12:03:27.950: E/AndroidRuntime(25520): FATAL EXCEPTION: main
  10-22 12:03:27.950: E/AndroidRuntime(25520): java.lang.NullPointerException
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at com.bambeeq.conferencecall.CheckBoxListViewAdapter$1.onCheckedChanged(EcConferenceNumber.java:109)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.widget.CompoundButton.setChecked(CompoundButton.java:137)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.widget.CompoundButton.toggle(CompoundButton.java:92)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.widget.CompoundButton.performClick(CompoundButton.java:104)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.view.View$PerformClick.run(View.java:17420)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.os.Handler.handleCallback(Handler.java:615)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.os.Handler.dispatchMessage(Handler.java:92)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.os.Looper.loop(Looper.java:137)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at android.app.ActivityThread.main(ActivityThread.java:4944)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at java.lang.reflect.Method.invokeNative(Native Method)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at java.lang.reflect.Method.invoke(Method.java:511)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
  10-22 12:03:27.950: E/AndroidRuntime(25520):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>I got struct here.Any answer will be help full</p>