def create_view(self, index, viewclass=None):
"""Creates and initializes the view for the data at `index`. The
returned view is synced with the data, except for the pos/size
properties.
"""
if viewclass is None:
viewclass = self.get_viewclass(index)
if viewclass is None:
return
item = self[index]
# FIXME: we could pass the data though the constructor, but that wont
# work for kv-declared classes, and might lead the user to think it can
# work for reloading as well.
view = viewclass()
if viewclass not in _view_base_cache:
_view_base_cache[viewclass] = isinstance(view, RecycleViewMixin)
if _view_base_cache[viewclass]:
view.refresh_view_attrs(self.recycleview, item)
else:
for key, value in item.items():
setattr(view, key, value)
return view
评论列表
文章目录