-
-
Save androidessence/67c47f774b972fdcf4c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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