我在使用数据绑定和包含标签时遇到以下错误:
Error:Execution failed for task ':app:dataBindingProcessLayoutsBetaDebug'.>data binding error msg:Only one layout element and one data element are allowed. [path to file] has 3file:[path to file]****\ data binding error ****
Run Code Online (Sandbox Code Playgroud)
这是我的布局文件:
[...]
<LinearLayout
android:id="@+id/activity_description_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<include
android:id="@+id/activity_description_header_bottom"
layout="@layout/activity_description_header_bottom" />
<include
android:id="@+id/activity_description_contact_info"
layout="@layout/activity_description_contact_info" />
<include
android:id="@+id/activity_description_other_info_box"
layout="@layout/activity_description_other_info_box" />
<include
android:id="@+id/activity_description_bottom_buttons"
layout="@layout/activity_description_bottom_buttons" />
</LinearLayout>
[...]
</layout>
Run Code Online (Sandbox Code Playgroud)
在每个包含的布局中,我有这样的东西:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
[...]
</layout>
Run Code Online (Sandbox Code Playgroud)
从这个回复:Android数据绑定使用包含标签我想我的代码是正确的,为什么数据仓认为我在文件中使用多个单个标签?
更新到Android studio 2.0预览版2后,在编译具有后缀.beta的beta风格时出现以下错误:
app build.gradle:
productFlavors {
beta {
applicationId 'com.example.app.beta'
}
production {
applicationId 'com.example.app'
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
Error:(38, 44) error: package com.example.app.databinding does not exist
Run Code Online (Sandbox Code Playgroud)
在编制生产风味时,一切都很好.最令人费解的是,只有在运行应用程序时才会出现此错误(不在gradle sync期间)
假设我们有一个应用程序,其中用户有一个日历,他可以在其中选择他想要获取事件列表的日期。当用户选择日期时,我们添加一个事件CalendarSelectedDateChanged(DateTime)。每次我们收到此类事件时,Bloc 组件都会从 API 获取数据。我们可以想象一下以不同的延迟收到响应的情况。这将产生以下场景:
预期结果是我们在这里丢弃请求 date=1 的响应
我们如何以最优雅的方式解决这种竞争条件(最好同时解决应用程序中的所有 BLoC)?
这是会产生此类问题的示例代码:
class ExampleBloc extends Bloc<ExampleEvent, ExampleState> {
ExampleBloc()
: super(ExampleDataLoadInProgress(DateTime.now())) {
on<ExampleSelectedDateChanged>((event, emit) async {
await _fetchData(event.date, emit);
});
}
Future<void> _fetchData(DateTime selectedDate,
Emitter<ExampleState> emit,) async {
emit(ExampleDataLoadInProgress(selectedDateTime));
try {
final data = callAPI(selectedDateTime);
emit(ExampleDataLoadSuccess(data, selectedDate));
} on ApiException catch (e) {
emit(ExampleDataLoadFailure(e, selectedDateTime));
}
}
}
Run Code Online (Sandbox Code Playgroud)