I'm trying to make a RecyclerView
, where each recycleritem has 3 radio button options.
Each of the radio butttons is related to an item in the object list that was passed to the adapter as a parameter.
How do I get the selected radio button selected? Do I have to do something with the radios buttons in the onBindViewHolder
method?
Below is my adapter:
public class LikeListAdapter extends RecyclerView.Adapter<LikeListAdapter.LikeItemViewHolder> {
private List<Goals> goalsList;
public LikeListAdapter(List<Goals> goalsList) {
this.goalsList = goalsList;
}
@Override
public LikeItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
// Inflate the custom layout
View view = inflater.inflate(R.layout.recycler_item_like, parent, false);
return new LikeItemViewHolder(view);
}
@Override
public void onBindViewHolder(LikeItemViewHolder holder, int position) {
Goals goals = goalsList.get(position);
if (goals != null && getItemCount() > 0) {
holder.goalsDescriptionTextView.setText(goals.getDescription());
}
}
@Override
public int getItemCount() {
return goalsList.size();
}
public class LikeItemViewHolder extends RecyclerView.ViewHolder implements RadioGroup.OnCheckedChangeListener {
@Bind(R.id.description_goalsTextView)
TextView goalsDescriptionTextView;
@Bind(R.id.happy_radio)
RadioButton happyRadioButton;
@Bind(R.id.soso_radio)
RadioButton sosoRadioButton;
@Bind(R.id.angry_radio)
RadioButton angryRadioButton;
@Bind(R.id.radio_like)
RadioGroup radioLike;
public LikeItemViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
radioLike.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.e("group","" + group);
Log.e("checkedId","" + checkedId);
switch (group.getId()) {
case (R.id.happy_radio):
Log.e("aqui", "happy");
break;
case (R.id.soso_radio):
Log.e("aqui", "soso");
break;
case (R.id.angry_radio):
Log.e("aqui", "angry");
break;
}
}
}
}