RecycleView: id: my_list scroll_type: ['bars', 'content'] scroll_wheel_distance: dp(114) bar_width: dp(8) viewclass: 'Tits' RecycleBoxLayout: default_size: None, dp(36) default_size_hint: 1, None size_hint_y: None height: self.minimum_height orientation: 'vertical' spacing: dp(2)
<SelectableLabel>:
# Draw a background to indicate selection
canvas.before:
Color:
rgba: (0.5, 0.2, 0.1, 1) if self.selected else (0.5, 0.5, 0.5, 1)
Rectangle:
pos: self.pos
size: self.size
# This is within whatever the main class is not within the above class, basically just# adjust some of these properties in your current declaration you have below. RecycleView: id: rv
scroll_type: ['bars', 'content'] scroll_wheel_distance: dp(114)
bar_width: dp(10) viewclass: 'SelectableLabel' SelectableRecycleBoxLayout: default_size: None, dp(56)
default_size_hint: 1, None size_hint_y: None height: self.minimum_height orientation: 'vertical'
multiselect: False touch_multiselect: False
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
RecycleBoxLayout):
""" Adds selection and focus behaviour to the view. """
class SelectableLabel(RecycleDataViewBehavior, Label):
""" Add selection support to the Label """
index = None
selected = BooleanProperty(False)
selectable = BooleanProperty(True)
def refresh_view_attrs(self, rv, index, data):
""" Catch and handle the view changes """
self.index = index
return super(SelectableLabel, self).refresh_view_attrs(
rv, index, data)
def on_touch_down(self, touch):
""" Add selection on touch down """
if super(SelectableLabel, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos) and self.selectable:
return self.parent.select_with_touch(self.index, touch)
def apply_selection(self, rv, index, is_selected):
""" Respond to the selection of items in the view. """
self.selected = is_selected
if is_selected:
print("selection changed to {0}".format(rv.data[index]))