找不到符号导入yodgorbekkomilov.edgar.footballapp.databinding.FootballItemBindingImpl

时间:2020-06-25 16:06:00

标签: android kotlin mvvm data-binding two-way-binding

我正在开发足球静态应用程序,但是当我运行代码时,我却遵循异常

找不到符号 导入yodgorbekkomilov.edgar.footballapp.databinding.FootballItemBindingImpl; ^ 符号:类FootballItemBindingImpl

在XML类下面

<?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">
<data>
    <variable
        name="viewModel"
        type="yodgorbekkomilov.edgar.footballapp.ui.FootballViewModel" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.clubName}"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.countryName}"/>





    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.clubValue}"/>

    <ImageView
        app:imageUrl="@{viewModel.image}"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:id="@+id/clubImage"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:mutableText="@{viewModel.europeanTitle}"/>


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

在我使用了数据绑定的FootballAdapter.kt下面

import android.os.Build

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import yodgorbekkomilov.edgar.footballapp.FootballResponse
import yodgorbekkomilov.edgar.footballapp.R
import yodgorbekkomilov.edgar.footballapp.databinding.FootballItemBinding
import yodgorbekkomilov.edgar.footballapp.ui.FootballViewModel


    class FootballAdapter :
        RecyclerView.Adapter<FootballAdapter.ViewHolder>() {
    
       private lateinit var footballList: List<FootballResponse>
    
        fun updatePostList(footballList: List<FootballResponse>) {
            this.footballList = footballList
            notifyDataSetChanged()
        }
    
        override fun onCreateViewHolder(
            parent: ViewGroup,
            viewType: Int
        ): FootballAdapter.ViewHolder {
            val binding: FootballItemBinding = DataBindingUtil.inflate(
                LayoutInflater.from(parent.context),
                R.layout.football_item,
                parent,
                false
            )
    
            return ViewHolder(binding)
        }
    
        override fun getItemCount(): Int {
            return footballList.size
        }
    
    
        @RequiresApi(Build.VERSION_CODES.O)
        override fun onBindViewHolder(holder: FootballAdapter.ViewHolder, position: Int) {
            holder.bind(footballList[position])
    
    
        }
    
    
        class ViewHolder(private val binding: FootballItemBinding) : RecyclerView.ViewHolder(binding.root) {
    
    
            private val viewModel = FootballViewModel()
    
            fun bind(model: FootballResponse) {
    
                viewModel.bind(model)
                binding.viewModel = viewModel
    
    
    
    
    
            }
    
        }
    }

在FootballViewModel.kt下面

import androidx.lifecycle.MutableLiveData
import yodgorbekkomilov.edgar.footballapp.FootballResponse
import yodgorbekkomilov.edgar.footballapp.base.BaseViewModel

class FootballViewModel: BaseViewModel() {
    private val clubName = MutableLiveData<String>()

    private val countryName = MutableLiveData<String>()
    private val clubValue = MutableLiveData<String>()
    private val clubImage = MutableLiveData<String>()
    private val europeanTitle = MutableLiveData<String>()

    fun bind(football: FootballResponse){
        clubName.value= football[0].name
        countryName.value = football[1].country
        clubValue.value = football[2].value.toString()
        clubImage.value = football[3].image
        europeanTitle.value = football[4].europeanTitles.toString()

    }

    fun getClubName():MutableLiveData<String>{
        return clubName
    }

    fun getCountryName():MutableLiveData<String>{
        return countryName
    }

    fun getClubValue():MutableLiveData<String>{
        return clubValue
    }

    fun getImage():MutableLiveData<String> {
 return clubImage

    }


    fun getEuropeanTitle():MutableLiveData<String> {
        return europeanTitle

    }
}

在我的app.gradle下面

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 29
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "yodgorbekkomilov.edgar.footballapp"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildFeatures{
        dataBinding = true
        viewBinding = true
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

    def room_version = "2.2.5"
    def nav_version = "2.3.0"
    //Navigation component
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    //RxJava
    implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
    implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
    implementation "com.squareup.retrofit2:adapter-rxjava2:2.6.1"
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'

    //Room
     implementation "androidx.room:room-rxjava2:$room_version"

    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'

    //Glide
    implementation 'com.github.bumptech.glide:glide:4.11.0'

    //Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.6.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.2'


    implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'

    //Dagger2
    implementation 'com.google.dagger:dagger:2.27'
    kapt 'com.google.dagger:dagger-compiler:2.27'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

我尝试过的 1.使缓存重启无效 2.我已经仔细检查了xml并没有解决问题 3.尝试同时遵循After migration to androidX: Databinding problem (Android Studio 4)ActivityMainBindingImpl cannot be found并没有解决我的问题

我想知道我在哪里犯错

0 个答案:

没有答案
相关问题