【发布时间】:2017-03-14 13:42:23
【问题描述】:
我正在尝试在没有任何绑定数据的情况下使用数据绑定到主布局上的 TextViews 等小部件,但是当我运行应用程序时出现此错误:
只允许一个布局元素和一个数据元素
主布局:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:slidingLayer="http://schemas.android.com/apk/res-auto">
<data>
</data>
<variable
name="presenter"
type="com.example.Ui.Register.Presenter.ActivityRegisterPresenter"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d1d1d1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/permission_for_read_contacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/permission_for_read_contacts"
android:textColor="@color/white"/>
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/default_textview_height"
android:text="@string/get_read_contact_permission"
android:background="@drawable/selector_blue_buttons"
android:clickable="@{()->presenter.getReadContactsPermission()}"
android:textColor="@color/white"/>
</LinearLayout>
<TextView
android:id="@+id/activity_register_view_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
</FrameLayout>
</layout>
在这个活动中,我默认没有任何绑定,例如setText,删除此行后:
<variable
name="presenter"
type="com.example.Ui.Register.Presenter.ActivityRegisterPresenter"/>
问题解决了!!
public class ActivityRegisterPresenter {
private ActivityRegisterContract.View view;
public ActivityRegisterPresenter(ActivityRegisterContract.View mView) {
view = mView;
}
public void getReadContactsPermission(){
view.getReadContactsPermission();
}
}
【问题讨论】:
标签: android data-binding android-databinding