Skip to content

Instantly share code, notes, and snippets.

@androidessence
Last active January 18, 2016 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save androidessence/67c47f774b972fdcf4c2 to your computer and use it in GitHub Desktop.
Save androidessence/67c47f774b972fdcf4c2 to your computer and use it in GitHub Desktop.
public class MyAdapter {
private List<MyItem> mDataSource;
private int mSelectedPosition;
private void selectPosition(int position) {
// Set the selected position.
this.mSelectedPosition = position;
// Loop through our data source.
for(int i = 0; i < mDataSource.size(); i++) {
// If the index of our loop is the position that was selected, set isChecked to true.
// Otherwise, isChecked should be false.
// Replace with necessary code to shutoff radio button.
mDataSource.get(i).isChecked = (i == mSelectedPosition);
}
// May need to revalidate
notifyDataSetChanged();
}
public class MyViewHolder implements View.OnClickListener {
public MyViewHolder(View view) {
super(view);
view.setOnClickListener(this);
}
@Override
public void onClick() {
// Select position that was clicked.
selectPosition(getAdapterPosition);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment