title: Use radio button in RecyclerView to allow only 1 selection
body: <p>I'm trying to use RadioButtons in a RecyclerView and I only want the user to be able to select one item. So if the user selects one the previously selected needs to be deselected. I am trying to handle this inside my onBindView method. This is the code in my adapter:</p>
  
  <pre><code>public class SelectCategoryAdapter extends RecyclerView.Adapter&lt;SelectCategoryAdapter.MyViewHolder&gt; {
  
      private Context mContext;
      private List&lt;Category2&gt; categoryList;
      private Category2 category;
      private RadioButton radioButton;
  
      public class MyViewHolder extends RecyclerView.ViewHolder {
          public TextView title, count, nameCategory;
  
          public MyViewHolder(View view) {
              super(view);
              nameCategory = (TextView) view.findViewById(R.id.edittext_category);
              count = (TextView) view.findViewById(R.id.count);
              radioButton = (RadioButton) view.findViewById(R.id.radio1);
              //overflow = (ImageView) view.findViewById(R.id.overflow);
          }
      }
  
  
      public SelectCategoryAdapter(Context mContext, List&lt;Category2&gt; categoryList, RadioButton radioButton) {
          this.mContext = mContext;
          this.categoryList = categoryList;
          this.radioButton = radioButton;
      }
  
      @Override
      public SelectCategoryAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.adapter_select_category, parent, false);
  
          return new SelectCategoryAdapter.MyViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(final SelectCategoryAdapter.MyViewHolder holder, final int position) {
          category = categoryList.get(position);
          holder.nameCategory.setText(category.getName());
          if (category.getTasks() &lt; 10){
              holder.count.setText(" " + Integer.toString(category.getTasks()) + " ");
          } else {
              holder.count.setText(Integer.toString(category.getTasks()));
          }
  
          holder.radioButton.setOnCheckedChangeListener(null);
          holder.radioButton.setChecked(position == radioButton);
          holder.radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  
                  radioButton = position;
                  notifyDataSetChanged();
              }
          });
  
      }
  
  
      @Override
      public int getItemCount() {
          return categoryList.size();
      }
  
  }
  </code></pre>
  
  <p>And this is the XML for the adapter:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;LinearLayout
          android:layout_below="@+id/toolbar"
          android:id="@+id/add_category_layout"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingRight="20dp"&gt;
  
          &lt;RadioButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="1"
              android:checked="true"
              android:id="@+id/radio1"
              android:paddingTop="20dp"
              android:paddingLeft="20dp"
              android:paddingRight="20dp"
              android:paddingBottom="20dp"
              /&gt;
  
          &lt;TextView
              android:id="@+id/edittext_category"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#494949"
              android:textSize="@dimen/s_text_size"
              android:paddingTop="20dp"
              android:paddingBottom="20dp"
              android:maxLines="1"/&gt;
  
          &lt;View
              android:layout_width="0dp"
              android:layout_height="0dp"
              android:layout_weight="1" /&gt;
  
          &lt;TextView
              android:id="@+id/count"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/circle"
              android:padding="3dp"
              android:text="20"
              android:textColor="@color/white"
              android:textSize="11sp"
              android:textStyle="bold"
              android:paddingLeft="20dp"
              android:paddingRight="20dp"/&gt;
      &lt;/LinearLayout&gt;
      &lt;View
          android:layout_width="fill_parent"
          android:layout_height="1dp"
          android:background="#ececec" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>So, the first error is that I'm getting a "cannot resolve symbol radioButton" and I don't know why this is happening, it's working for the other 2 TextViews but for the radio button I get this error. </p>