Android在DataBinding功能上获取重复属性 [英] Android get duplicate attribute on DataBinding feature
问题描述
我是使用android dataBinding
功能的新手,当我成功地将一项活动更改为使用dataBinding
功能时,我在进行其他活动时遇到了错误,并且找不到任何问题
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
我收到此错误:
Error parsing XML: duplicate attribute
duplicate attribute
是什么意思?哪个属性?
What does mean duplicate attribute
? which 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();
}
}
什么问题以及如何解决?
whats problem and how can i resolve that?
推荐答案
此错误的原因是您正在使用
The reason for this error is that you are using
xmlns:android="http://schemas.android.com/apk/res/android"
在两个地方.仅使用该行的布局标签,然后从LinearLayout中删除即可解决您的问题
at two places. use the line only the layout tag and remove from LinearLayout solve your problem
这篇关于Android在DataBinding功能上获取重复属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!