title: Getting Switch state in ListView
body: <p>in my Application I want the user to make multiple choices and for this i present some Switch in a ListView and a button to confirm.</p>
  
  <p>The problem is, when I inserted the values in db in the Button onClickListener() function, i can retrieve from the switches the text, but not the state of them (in the example, always output true)</p>
  
  <pre><code>btn.setOnClickListener( new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              ListAdapter adapter = list.getAdapter();
              MyDatabase db = new MyDatabase(cntx);
              db.open();
              for(int n=0;n&lt;adapter.getCount();n++)
              {
                  View rowview = adapter.getView(n, null, null);
                  Switch swtc = (Switch) rowview.findViewById(R.id.switch1);
                  String[] args = {(String)swtc.getText()};
                  if(swtc.isChecked())
                  {
                      Log.i("update", args[0]+" going to be true");
                  }
                  else
                  {
                      Log.i("update", args[0]+" going to be false");
  
                  }
                  int a = db.updateAlert(swtc.isChecked(), MyDatabase.Tab_Cal_Set.Cal+"=?", args);
                  Toast.makeText(cntx, "affected: "+Integer.toString(a), Toast.LENGTH_LONG).show();
              }
              db.close();
  
          }
      });
  </code></pre>
  
  <p>PS: adapter is the arrayadapter I've created for the ListView, cntx is the context of the application, and MyDatabase is my custom class that provide to manage an Sqlite Database. Hope you can help me</p>
  
  <p>code of arrayadapter:</p>
  
  <pre><code> public class NotificationElementList extends ArrayAdapter&lt;String&gt;{
  
  private final Activity context;
  
  private final List&lt;String&gt; titles;
  private final List&lt;String&gt; imgs;
  private final List&lt;Boolean&gt; alert;
  
  
  public NotificationElementList(Activity context, List&lt;String&gt; titles, List&lt;String&gt; imgs, List&lt;Boolean&gt; alert) {
  
      super(context, R.layout.list_single, titles);
      this.context = context;
      this.titles = titles;
      this.imgs = imgs;
      this.alert = alert;
  
      }
  
  @Override
  public View getView(int position, View view, ViewGroup parent) {
  
      LayoutInflater inflater = context.getLayoutInflater();
  
      View rowView= inflater.inflate(R.layout.notification_list_element, null, true);
  
      Switch switch_text = (Switch) rowView.findViewById(R.id.switch1);
      switch_text.setChecked(alert.get(position));
      switch_text.setText(titles.get(position));
  
      return rowView;
      }
  </code></pre>
  
  <p>}</p>