evant / binding-collection-adapter

Easy way to bind collections to listviews and recyclerviews with the new Android Data Binding framework
Apache License 2.0
1.92k stars 255 forks source link

How to get a reference to inner view of itembinding #176

Closed edlman closed 4 years ago

edlman commented 4 years ago

I'm trying to get a reference to inner view (VideoView) of a page in PagerView. There is a fragment XML definition which contains

        <androidx.viewpager.widget.ViewPager
            android:id="@+id/pager"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/tabs"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:items="@{vm.items}"
            app:itemBinding="@{vm.itemBinding}"/>

The ViewModel class contains

    val items = MutableLiveData<List<TutorialScreenModel>>()
    val itemBinding = ItemBinding.of<TutorialScreenModel>(BR.model, R.layout.page_tutorial).bindExtra(BR.listener, this)

and page_tutorial.xml layout contains

        ...
        <VideoView
            android:id="@+id/videoView"
            ....

And I want to get reference to this VideoView. But I didn't find a way how to. It's not possible via itemBinding.

evant commented 4 years ago

Not directly. You can either subclass the adapter and get a reference to it in onBindBinding or pass the view to the model you are binding in xml.

edlman commented 4 years ago

Hello Evan,

thanks for reply. I did it using my own adapter. But it's a pitty it's not possible to access inner views on ItemBinding.

Regards, Martin

Not directly. You can either subclass the adapter and get a reference to it in |onBindBinding| or pass the view to the model you are binding in xml.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/evant/binding-collection-adapter/issues/176?email_source=notifications&email_token=AA5XIQHFPHF4JHZWXFSW5S3Q73N7JA5CNFSM4KL4URCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ7O7PA#issuecomment-578744252, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5XIQAJROE6WN2ON36PIXTQ73N7JANCNFSM4KL4URCA.

-- Martin Edlman [web] http://an.y-co.de ANY CODE [mobile] +420 774 692 633 c/c++,c#,java,android, [hangout] ac.anycode @ gmail.com php,sql,html5,css3 [skype] an.y-co.de