0

There is an app:items="" attribute for RecyclerView, how is this attribute used with MVVM and android.arch.lifecycle.ViewModel, not ViewModel that extends BaseObservable? items could be LiveData, List or ObservableArrayList, with which collection should it be used?

Thracian
  • 43,021
  • 16
  • 133
  • 222
  • you need a BindingAdapter for that – Blackbelt Jun 28 '18 at 08:48
  • Isn't it possible without @BindingAdapter? – Thracian Jun 28 '18 at 08:49
  • no unfortunately it is not (AFAIK). – Blackbelt Jun 28 '18 at 08:50
  • So we can't just directly bind a collection from ViewModel to RecyclerView. Do you have a link for an example, or tutorial? – Thracian Jun 28 '18 at 08:51
  • 1
    `RV` doesn't deal with the dataset. It is its adapter. – Blackbelt Jun 28 '18 at 08:52
  • Yes, you might be right. However, i thought i've seen somewhere that it was used as app:items=“@{viewModel.items}”, i will post source if it's ViewModel from arch and does not use @BindingAdapter. Thanks. – Thracian Jun 28 '18 at 08:55
  • I would really love to see that. – Blackbelt Jun 28 '18 at 08:56
  • where did you see those `app:items`? there is no such attribute in any support `recyclerview-v7` library – pskink Jun 28 '18 at 08:57
  • @pskink, i'm studying MVVM and data binding about a week. I'm searching for sub topics and i think i saw it was used in some github projecte, but i wasn't looking for this then, so i'm not sure. I will look for it specifically and post if it's used with ViewModel from arch library. – Thracian Jun 28 '18 at 09:00
  • @pskink, yes there is `app:items` attribute for RecyclerView, i'm not sure how it's used with MVVM. – Thracian Jun 28 '18 at 09:01
  • so where it is defined? what binding adapter implements it? [here](https://android.googlesource.com/platform/frameworks/data-binding/+/716ba89/extensions/baseAdapters/src/main/java/android/databinding/adapters) you have binding adapters for std android views, so where is that adapter for `RecyclerView`? – pskink Jun 28 '18 at 09:03
  • When you type items for RV in AS, it autocompletes it, however you should import architecture components in gradle. You should ask blackbelt how it's used with @BindingAdapter. I'm asking if it's possible to use with ViewModel. – Thracian Jun 28 '18 at 09:05
  • i would bet you could get `items` in autocomplete for `TextView` too, so... – pskink Jun 28 '18 at 09:07
  • Yes, you are right. I do see it for other views too in a project with arch components, otherwise it does no appear. I found the project https://github.com/evant/binding-collection-adapter. I will look into this – Thracian Jun 28 '18 at 09:12
  • https://github.com/evant/binding-collection-adapter/tree/master/bindingcollectionadapter-recyclerview/src/main/java/me/tatarka/bindingcollectionadapter2 – pskink Jun 28 '18 at 09:14
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173950/discussion-between-thracian-and-pskink). – Thracian Jun 28 '18 at 09:15

0 Answers0