title: Using Radio button with recyclerview in android
body: <h2>This is my code for single selection in the recyclerview. I am able to select single choice in the recycler list but when i deselect the radiobutton then i have to click twice on the radio button to again enable is i.e to select the radiobutton again. Can any one help me with this....</h2>
  
  <pre><code>import android.content.Context;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.CompoundButton;
  import android.widget.RadioButton;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class Address_Adapter extends RecyclerView.Adapter&lt;Address_Adapter.AddresssHolder&gt;{
  
      private List&lt;Model_Address&gt; listData;
      private LayoutInflater inflater;
      private Context context;
      private RadioButton rbChecked = null;
      private int rbPosoition = 0;
  
      public Address_Adapter(List&lt;Model_Address&gt; listData, Context context) {
          this.listData = listData;
          this.context = context;
          this.inflater = LayoutInflater.from(context);
      }
  
      @Override
      public AddresssHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view = inflater.inflate(R.layout.layout_recycler_address, parent,false);
          return new AddresssHolder(view,listData,context);    }
  
      @Override
      public void onBindViewHolder(final AddresssHolder holder, final int position) {
          Model_Address item = listData.get(position);
          holder.address.setText(item.getAddress());
          holder.state.setText(item.getState());
          holder.pin_code.setText(item.getPin_code());
          holder.contact.setText(item.getContact());
  
          if (holder.selected.isChecked()){
              rbPosoition = holder.getAdapterPosition();
              Toast.makeText(context, "" + rbPosoition, Toast.LENGTH_SHORT).show();
          }
  
      }
  
      @Override
      public int getItemCount() {
          return listData.size();
      }
  
      public class AddresssHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  
          private TextView address, state, pin_code, contact;
          private RadioButton selected;
          private  View container;
          private  List&lt;Model_Address&gt; listData;
          private Context context;
  
          public AddresssHolder(View itemView,List&lt;Model_Address&gt; listdata,Context context) {
              super(itemView);
              this.listData = listdata;
              this.context = context;
              itemView.setOnClickListener(this);
              address = (TextView) itemView.findViewById(R.id.text_address);
              state = (TextView) itemView.findViewById(R.id.state_text);
              pin_code = (TextView) itemView.findViewById(R.id.pin_code_text);
              contact = (TextView) itemView.findViewById(R.id.contact_text);
              selected = (RadioButton) itemView.findViewById(R.id.select_radioButton);
              if (rbPosoition == 0 &amp;&amp; selected.isChecked())
              {
                  rbChecked = selected;
                  rbPosoition = 0;
              }
              selected.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      RadioButton rb = (RadioButton) v;
                      int clickedPos = getAdapterPosition();
                      if (rb.isChecked()){
                          if(rbChecked != null)
                          {
                              rbChecked.setChecked(false);
                          }
                          rbChecked = rb;
                          rbPosoition = clickedPos;
                      }
                      else{
                          rbChecked = null;
                          rbPosoition = 0;
                      }
  
                  }
              });
  
          }
  
          @Override
          public void onClick(View v) {
              int positenter code hereion = getAdapterPosition();
          }
      }
  }
  </code></pre>