title: Unable to toggle switch to on mode in List View in android studio
body: <p>I am Using <code>ListView</code> to fetch the names from the database and while the user clicks on the switch it has to move to next activity using Intent which I have given using <code>onClickListener</code>, but the switch doesn't change to on mode when I click it. I am able to move to next activity and see the textviews which I am sending, is it possible to also toggle the switch using position of the switch button?</p>
  <p><strong>Java code:</strong></p>
  <pre><code>public ListAdapter GetInspList() {
          ArrayList&lt;Integer&gt; pos = new ArrayList&lt;&gt;();
  
          ListView listView = (ListView) findViewById(R.id.inspection_listview_1);
          List&lt;Map&lt;String, String&gt;&gt; MyDataList = getinspectionlist();
  
          String[] f = {&quot;Inspection_Name&quot;, &quot;Inspection_Id&quot;, &quot;Button&quot;};
         int[] i = {R.id.inspec_list_name, R.id.inspec_list_id, R.id.nok_1};
          SimpleAdapter ad;
          final int[] popo = {0};
          ad = new SimpleAdapter(this, MyDataList, R.layout.inspection_listview, f, i) {
  
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                  View v = super.getView(position, convertView, parent);
                  nok_1 = v.findViewById(R.id.nok_1);
                 // clear.setText(&quot;Clear&quot;);
                  nok_1.setOnClickListener(arg0 -&gt; {
                      // TODO Auto-generated method stub
                      ListAdapter add = listView.getAdapter();
                      listView.setAdapter(add);
                      //Log.e(&quot;here&quot;, MyDataList.get(position).get(&quot;Activity_Name&quot;));
                      
                      String d = (String) MyDataList.get(position).get(&quot;Inspection_Name&quot;);
                             String vinno = vin.getText().toString().trim();
                              //String inspname = d.getText().toString().trim();
                              String inspname = d.trim();
                              Bundle bundle = new Bundle();
                              bundle.putString(&quot;vinno&quot;, vinno);
                           bundle.putString(&quot;inspname&quot;, inspname);
                             Intent intent = new Intent(Inspection.this, NOK_inspection.class);
                             intent.putExtras(bundle);
                             startActivity(intent);
                  });
  
                  return v;
              }
          };
          listView.setAdapter(ad);
          ad.notifyDataSetChanged();
  
  
          return listView.getAdapter();
      }
  
  
      public List&lt;Map&lt;String, String&gt;&gt; getinspectionlist() {
  
          List&lt;Map&lt;String, String&gt;&gt; data = null;
          data = new ArrayList&lt;Map&lt;String, String&gt;&gt;();
          try {
  
              ConnectionHelper connectionHelper = new ConnectionHelper();
              connect = connectionHelper.connectionClass();
              if (connect != null) {
                  String query = &quot;select * from Config_Inspection&quot;;
                  Statement st = connect.createStatement();
                  ResultSet rs = st.executeQuery(query);
                  while (rs.next()) {
                      Map&lt;String, String&gt; dtname = new HashMap&lt;String, String&gt;();
                      dtname.put(&quot;Inspection_Name&quot;, rs.getString(3));
                      dtname.put(&quot;Inspection_Id&quot;, rs.getString(2));
                      // dtname.put(&quot;Activity_Value&quot;, rs.getString(7));
  
                      data.add(dtname);
  
  
                  }
  
  
              }
  
  
          } catch (Exception ex) {
  
          }
          return data;
  
      }
  </code></pre>
  <p><strong>XML of list view file:</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;horizontal&quot;&gt;
  
      &lt;TextView
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;100dp&quot;
          android:textSize=&quot;17dp&quot;
          android:layout_weight=&quot;0.8&quot;
          android:id=&quot;@+id/inspec_list_name&quot;
          /&gt;
      &lt;TextView
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;0dp&quot;
          android:id=&quot;@+id/inspec_list_id&quot;/&gt;
  
      &lt;View
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_weight=&quot;0.01&quot;/&gt;
      &lt;TextView
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;OK&quot;
          android:textSize=&quot;17dp&quot;
          android:layout_marginTop=&quot;10dp&quot;
          android:layout_weight=&quot;0.02&quot;/&gt;
      &lt;View
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_weight=&quot;0.01&quot;/&gt;
      &lt;Switch
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:id=&quot;@+id/nok_1&quot;
          android:layout_marginTop=&quot;10dp&quot;
          android:scaleX=&quot;1.2&quot;
          android:scaleY=&quot;1.2&quot;
          android:thumbTint=&quot;@color/ok_button_color&quot;
          android:trackTint=&quot;@color/nok_button_color&quot;
  
          /&gt;
      &lt;View
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_weight=&quot;0.01&quot;/&gt;
      &lt;TextView
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;10dp&quot;
          android:text=&quot;NOK&quot;
          android:textSize=&quot;17dp&quot;
          android:layout_weight=&quot;0.02&quot;/&gt;
  
  
  
  &lt;/LinearLayout&gt;
  </code></pre>