Android在DataBinding功能上获得重复属性

时间:2016-10-03 17:31:59

标签: android android-databinding

我是使用Android dataBinding功能的新手,当我成功将其中一个活动更改为使用dataBinding功能时,我会收到其他活动的错误,而我无法找到问题

我收到此错误:

Error parsing XML: duplicate attribute

什么意思是duplicate attribute?哪个属性?

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="newChannelViewModel"
            type="com.pishguy.androidapplication.appname.Views.Activities.CreateNewChannel.CreateNewChannelViewModel"/>
    </data>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/content_background"
        android:orientation="vertical">

        <include layout="@layout/new_channel_application_toolbar"/>

        <com.pishguy.androidapplication.appname.Widgets.ViewPagerCustomDuration
            android:id="@+id/create_new_channel"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="-25dp"
            android:layout_marginRight="-25dp"/>
    </LinearLayout>
</layout>

这是我的活动:

public class CreateNewChannel extends ActivityBase implements ActivityBase.connections, CreateNewChannelViewModel.OnActionListener {

...

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    }

    super.onCreate(savedInstanceState);
    /** Set connection Listener */
    setRealTimeConnectionListener(this);

    CreateNewChannelBinding   binding           = DataBindingUtil.setContentView(this, R.layout.create_new_channel);
    CreateNewChannelViewModel newChannelViewModel = new CreateNewChannelViewModel(this);
    binding.setNewChannelViewModel(newChannelViewModel);

    ButterKnife.bind(this);

    ...

}

此活动ViewModel

public class CreateNewChannelViewModel extends BaseObservable implements ViewModel {

    private OnActionListener ionActionListener;
    public CreateNewChannelViewModel(OnActionListener onActionListener) {
        ionActionListener = onActionListener;
    }

    @Override
    public void destroy() {
    }

    public interface OnActionListener {
        void onClick();
    }
}

什么问题,我该如何解决?

1 个答案:

答案 0 :(得分:0)

此错误的原因是您正在使用

xmlns:android="http://schemas.android.com/apk/res/android"

在两个地方。仅使用该行的布局标签,然后从LinearLayout中删除即可解决您的问题