Reputation: 354
I'm trying to bind view from adapter but it throws error
xml file
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="accessHistoryItem"
type="com.example.api.model.response.AccessListItem" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="122dp"
android:layout_margin="30dp">
<View
android:id="@+id/borderLine"
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@color/black"
app:borderLine="@{accessHistoryItem}"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="0dp"
android:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
binding adapter
@BindingAdapter("borderLine")
fun View.borderLine(item: AccessListItem?){
item.let {
}
exception
Cannot find a setter for <android.view.View app:borderLine> that accepts parameter type 'com.example.api.model.response.AccessListItem' If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches. Open File
gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example"
minSdkVersion 28
targetSdkVersion 30
versionCode 19
versionName "0.7.1"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
applicationVariants.all{
variant ->
variant.outputs.each{
output->
project.ext { appName = 'example' }
def formattedDate = new Date().format('dd-MM-yyyy')
// on below line we are creating a new name for our apk.
def newName = output.outputFile.name
newName = newName.replace("app-", "$project.ext.appName-v${variant.versionName}_${variant.versionCode}-$formattedDate-")
output.outputFileName = newName
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
dataBinding{
enabled = true
}
}
dependencies {
implementation project(":api")
//rx
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
//gson
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
//glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
api 'com.google.android.material:material:1.1.0-alpha06'
apply plugin: 'kotlin-kapt'
}
Upvotes: 1
Views: 272
Reputation: 1463
From your provided code snippets, there doesn't seem to be anything wrong with it. I suspect missing plugin in the app-level build gradle file. Add id 'kotlin-kapt'
to the plugins.
Upvotes: 1