Android get duplicate attribute on DataBinding fea

2019-07-29 03:38发布

I'm novice on using android dataBinding feature, when i successful change one of activity to using dataBinding feature i get error for other activity and i can't find whats problem

I get this error:

Error parsing XML: duplicate attribute

What does mean duplicate attribute? which attribute?

My Layout:

<?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>

and this is my Activity:

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);

    ...

}

and this activity 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();
    }
}

whats problem and how can i resolve that?

1条回答
Viruses.
2楼-- · 2019-07-29 04:22

The reason for this error is that you are using

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

at two places. use the line only the layout tag and remove from LinearLayout solve your problem

查看更多
登录 后发表回答