我想测试数据绑定的指南中给出这里.我已将其包含在我的build.gradle文件中(模块应用程序):
compileSdkVersion 'android-MNC'
buildToolsVersion '23.0.0 rc2'
Run Code Online (Sandbox Code Playgroud)
在项目build.gradle文件中,我已将其包含在我的依赖项中:
classpath "com.android.tools.build:gradle:1.3.0-beta2"
classpath "com.android.databinding:dataBinder:1.0-rc0"
Run Code Online (Sandbox Code Playgroud)
布局文件与指南中给出的文件完全相同.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.firstName}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.lastName}"/>
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
最初它给出了一个错误Element layout does not have the required attribute layout_width and layout_height
.
我尝试通过为两者分配match_parent来修复它.然后我Error parsing XML: duplicate attribute
在我指定的线layout_height
和layout_width
线性布局上得到了错误
.
我再次试图通过删除这些属性来解决这个问题.现在,每当我尝试编译时,我都会看到 - error: package my.package.name.databinding
不存在.
代码完成在我的Fragment中完美运行,我试图使用这个布局.
那么我错过了什么?
我最近开始开发一个使用数据绑定的android应用程序.我现在的问题是因为这个错误我无法运行应用程序:
Error:(10) Error parsing XML: duplicate attribute
Run Code Online (Sandbox Code Playgroud)
使用数据绑定(我正在使用片段)在每个文件中发生错误.我用Google搜索了3个小时,我找不到解决方案.
的build.gradle:
apply plugin: 'com.android.application'
android {
dexOptions {
preDexLibraries = false
javaMaxHeapSize "2g"
}
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "at.blacktasty.schooltoolmobile"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/eneter-messaging-android-7.0.1.jar')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0' …
Run Code Online (Sandbox Code Playgroud)