title: how to work with checkox in mvvm model in android
body: <p>I am working on Recyclerview in which checkboxes are there. I want to know how to use the below to achieve MVVM data binding in android.</p>
  
  <pre><code>@BindingAdapter({"app:setCheckBoxListener"})
  public static void setCheckBoxListener(AppCompatCheckBox checkBox, final OnCheckListener onCheckListener) {
      checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              onCheckListener.onCheckChanged(isChecked, (String) buttonView.getText());
          }
      });
  }
  </code></pre>
  
  <p>this is the ViewModel class which I am using for the logical part. I want when I check on the checkboxes the data will be saved in the ArrayList.</p>
  
  <pre><code>import android.content.Context;
  import android.content.SharedPreferences;
  import android.util.Log;
  import android.widget.Toast;
  
  import com.codestrela.product.adapters.SelectContactAdapter;
  import com.codestrela.product.data.Contact;
  import com.codestrela.product.fragments.ListDialogFragment;
  import com.google.gson.Gson;
  import com.google.gson.reflect.TypeToken;
  
  import java.lang.reflect.Type;
  import java.util.ArrayList;
  
  public class ListDialogViewModel {
      private static final String TAG = "ListDialogViewModel";
      public static final String CONTACT_LIST = "contact_list";
      public RowSelectContactViewModel viewModel;
      ListDialogFragment listDialogFragment;
      ArrayList&lt;RowSelectContactViewModel&gt; selectViewmodel;
      ArrayList&lt;Contact&gt; contacts;
      public SelectContactAdapter adapter;
  
      public ListDialogViewModel(ListDialogFragment listDialogFragment) {
          this.listDialogFragment = listDialogFragment;
          adapter = new SelectContactAdapter(new ArrayList&lt;RowSelectContactViewModel&gt;());
  
          selectViewmodel = new ArrayList&lt;&gt;();
          onContact();
      }
  
      public void onContact() {
          contacts = new ArrayList&lt;&gt;();
  
          SharedPreferences sharedPreferences = listDialogFragment.getActivity().getSharedPreferences("shared preference", Context.MODE_PRIVATE);
          Gson gson = new Gson();
          String json = sharedPreferences.getString(CONTACT_LIST, null);
          Toast.makeText(listDialogFragment.getActivity(), "" + json, Toast.LENGTH_SHORT).show();
          Type type = new TypeToken&lt;ArrayList&lt;Contact&gt;&gt;() {
          }.getType();
          contacts = gson.fromJson(json, type);
          Log.e(TAG, "array size: " + contacts.toString());
          for (int i = 0; i &lt; contacts.size(); i++) {
              viewModel = new RowSelectContactViewModel();
              String name = contacts.get(i).getName();
              viewModel.contactName.set(name);
              viewModel.contactNumber.set(contacts.get(i).getNumber());
              Toast.makeText(listDialogFragment.getActivity(), " check "+viewModel.contactCheckbox.get(), Toast.LENGTH_SHORT).show();
  
              selectViewmodel.add(viewModel);
          }
          adapter.addAll(selectViewmodel);
  
      }
  
  }
  </code></pre>
  
  <p>this is the row layout that I am using in the recycler view in the application. This checkbox is there which I am using in the application. Please help me I am very new at this.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
      &lt;data&gt;
          &lt;variable
              name="vm"
              type="com.codestrela.product.viewmodels.RowSelectContactViewModel" /&gt;
      &lt;/data&gt;
      &lt;androidx.cardview.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:cardCornerRadius="8dp"
          android:layout_margin="8dp"&gt;
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"&gt;
          &lt;CheckBox
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="8dp"
              android:checked="@{vm.contactCheckbox.get()}"
              android:layout_alignParentLeft="true"/&gt;
         &lt;LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="vertical"
             android:layout_margin="8dp"
             android:layout_gravity="center"&gt;
          &lt;TextView
              android:id="@+id/contact_name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@{vm.contactName}"
              android:layout_gravity="center"
              android:textSize="18dp"/&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@{vm.contactNumber}"
            android:textSize="14dp"
              android:layout_marginTop="4dp"
              android:layout_gravity="center"
              /&gt;
  
      &lt;/LinearLayout&gt;&lt;/LinearLayout&gt;&lt;/androidx.cardview.widget.CardView&gt;
  &lt;/layout&gt;
  </code></pre>