如何使用DataBinding获得对动态添加的视图的访问

时间:2018-12-03 20:08:57

标签: android android-custom-view android-databinding

我有以下xml:

<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<ui.widget.expandable_layout.ExpandableLayout
    android:id="@+id/expandablelayout_devicemgmtitem_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:detail_layout="@layout/item_devicemgmt_details"
    tools:ignore="UnusedAttribute">

    <TextView
        android:id="@+id/text_devicemgmtitem_sn"
        android:layout_width="0dp"
        android:layout_height="wrap_content" />

</ui.widget.expandable_layout.ExpandableLayout>

在我的ExpandableLayout类的init方法中,添加由属性传递的detail_view,如下所示:

final int eV = a.getResourceId(R.styleable.ExpandableLayout_detail_layout, -1);
expandableView =
                (eV != -1) ? LayoutInflater.from(getContext()).inflate(eV, this) : null;

当我将布局绑定到时:

binding = DataBindingUtil.inflate(LayoutInflater
            .from(parent.getContext()), R.layout.item_devicemgmt, parent, false)

我只能访问容器和textview。是否可以访问仅用一个绑定对象动态添加的dynamic_layout的视图?

0 个答案:

没有答案