publicclassMyHolderextendsKRecyclerViewHolder {
privateTextViewtitleLabel, descLabel;
publicMyHolder(ViewitemView) {
super(itemView);
titleLabel = (TextView) itemView.findViewById(R.id.titleLabel);
descLabel = (TextView) itemView.findViewById(R.id.descLabel);
}
@OverrideprotectedvoidsetSelected(@NonNullContextcontext, booleanselected) {
super.setSelected(context, selected);
// This method is called whenever the holder is selected/unselected.if (selected) {
// Selected
} else {
// Unselected
}
}
@OverrideprotectedvoidsetData(@NonNullContextcontext, @NonNullObjectitemObject) {
super.setData(context, itemObject);
// This method is called automatically by the adapter.// override this method and set your data here...// Check the type of itemObjectif (itemObjectinstanceofMyObject) {
MyObjectmyObject = (MyObject)itemObject;
titleLabel.setText(myObject.title);
descLabel.setText(myObject.description);
}
}
}
adapter.allowsSingleSelection = true; // Enables single selectionadapter.allowsMultipleSelection = true; // Enables multiple selectionadapter.deselectItemOnClickIfSelected = true; // Deselects the item if already selected.adapter.getSelectedIndexes(); // Get list of selected item positions