【问题标题】:Android get duplicate attribute on DataBinding featureAndroid 在 DataBinding 功能上获取重复属性
【发布时间】:2016-10-03 17:31:59
【问题描述】:

我是使用 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();
    }
}

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

【问题讨论】:

    标签: android android-databinding


    【解决方案1】:

    这个错误的原因是你正在使用

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

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

    【讨论】:

      猜你喜欢
      • 2017-02-27
      • 2015-11-29
      • 2013-04-05
      • 2022-06-03
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      • 2019-10-11
      相关资源
      最近更新 更多