title: ListView with checkboxes android studio
body: <p>I'm having trouble getting my checkboxes checked when any of the functions(which are commented out now) are called inside my listView onItemClickedListener. toggleChecked should only update my database and RefreshList is supposed to update my listView.
  My onItemClickListener</p>
  <pre><code>listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
                  ListItemDetails listItemDetails = (ListItemDetails) arrayAdapter.getItem(i);
  
                  //toggleChecked(i, view);
  
                  //RefreshList(arrayAdapter);
                  CheckBox checkBox = (CheckBox)view.findViewById(R.id.listitems_checkbox);
                  checkBox.setChecked(!checkBox.isChecked());
              }
          });
  </code></pre>
  <p>toggleChecked function</p>
  <pre><code>public void toggleChecked(final Integer i,final View view)
      {
          final DatabaseReference RootRef;
          RootRef = FirebaseDatabase.getInstance().getReference();
  
          RootRef.child(&quot;Lists&quot;).child(ListDetails.getID()).child(&quot;listitems&quot;).child(arrayList.get(i).getID()).child(&quot;checked&quot;).addListenerForSingleValueEvent(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot snapshot) {
                  String checked = snapshot.getValue(String.class);
                  Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
                  map.put(&quot;checked&quot;,(checked.equals(&quot;0&quot;) ? &quot;1&quot; : &quot;0&quot;));
  
                  RootRef.child(&quot;Lists&quot;).child(ListDetails.getID()).child(&quot;listitems&quot;).child(arrayList.get(i).getID()).updateChildren(map);
  
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError error) {
  
              }
          });
      }
  </code></pre>
  <p>RefreshList function</p>
  <pre><code>public void RefreshList(final ArrayAdapter&lt;ListItemDetails&gt; arrayAdapter) {
          DatabaseReference reference;
          reference=FirebaseDatabase.getInstance().getReference().child(&quot;Lists&quot;);
          reference.child(ListDetails.getID()).child(&quot;listitems&quot;).orderByChild(&quot;name&quot;).addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot snapshot) {
                  arrayList.clear();
                  for(DataSnapshot ds : snapshot.getChildren())
                  {
                      ListItemDetails temp = new ListItemDetails();
                      String name = ds.child(&quot;name&quot;).getValue(String.class);
                      temp.setName(name);
                      String ID = ds.child(&quot;ID&quot;).getValue(String.class);
                      temp.setID(ID);
                      String checked = ds.child(&quot;checked&quot;).getValue(String.class);
                      temp.setChecked(checked);
                      arrayList.add(temp);
                  }
                  listView.setAdapter(arrayAdapter);
  
                  for(int i=0; i&lt;listView.getAdapter().getCount(); i++)
                  {
                      View v = getViewByPosition(i,listView);
                      CheckBox checkBox = (CheckBox)v.findViewById(R.id.listitems_checkbox);
                      if(arrayList.get(i).getChecked().equals(&quot;1&quot;))
                      {
                          checkBox.setChecked(true);
                      }
                      else {
                          checkBox.setChecked(false);
                      }
                  }
              }
  
  
              @Override
              public void onCancelled(@NonNull DatabaseError error) {
  
              }
          });
      }
  </code></pre>
  <p>XML for the adapter</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout
      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:descendantFocusability=&quot;blocksDescendants&quot;&gt;
  
      &lt;TextView
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:textSize=&quot;35sp&quot;
          android:id=&quot;@+id/textt&quot;&gt;
      &lt;/TextView&gt;
      &lt;CheckBox
          android:id=&quot;@+id/listitems_checkbox&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;35dp&quot;
          android:layout_alignParentEnd=&quot;true&quot;
          android:clickable=&quot;false&quot;
          /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p>Adapter is declared like this</p>
  <pre><code>final ArrayAdapter arrayAdapter = new ArrayAdapter&lt;ListItemDetails&gt;(this, R.layout.list_items_checkbox, R.id.textt, arrayList);
  </code></pre>