简体   繁体   English

回收者查看firebase Kotlin

[英]Recycler View firebase Kotlin

Program type already present: android.arch.lifecycle.LiveData$LifecycleBoundObserver Message{kind=ERROR, text=Program type already present: android.arch.lifecycle.LiveData$LifecycleBoundObserver, sources=[Unknown source file], tool name=Optional.of(D8)} 程序类型已存在:android.arch.lifecycle.LiveData $ LifecycleBoundObserver消息{种类=错误,文本=程序已存在:android.arch.lifecycle.LiveData $ LifecycleBoundObserver,来源= [未知源文件],工具名称=可选。 ((D8)}

I have Error like that, please someone give me example of recyclerview with firebase-ui-database 3.1.3 because I have stack TT 我有这样的错误,请有人给我带firebase-ui-database 3.1.3的recyclerview示例,因为我有堆栈TT

this my HomeFragment 这是我的HomeFragment

   package com.fish.isyania.aplikasipemesananreparasi.fragment

import android.content.Context import android.net.Uri import android.os.Bundle import android.support.v4.app.Fragment import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.firebase.ui.database.FirebaseRecyclerAdapter import com.firebase.ui.database.FirebaseRecyclerOptions

import com.fish.isyania.aplikasipemesananreparasi.R import com.fish.isyania.aplikasipemesananreparasi.model.Promo import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.diskon_row.view.* import kotlinx.android.synthetic.main.diskon_row.view.promoImage


class HomeFragment : Fragment() {
    lateinit var mRecyclerView: RecyclerView
    lateinit var mDatabase: DatabaseReference
    lateinit var options : FirebaseRecyclerOptions<Promo>


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val rootView = inflater.inflate(R.layout.fragment_home, container, false)

        mDatabase = FirebaseDatabase.getInstance().getReference("Promo")
        mRecyclerView = rootView.findViewById(R.id.promoRc)
        mRecyclerView.setHasFixedSize(true)
        mRecyclerView.setLayoutManager(LinearLayoutManager(context))

        logRecyclerView()

        return rootView
    }

    private fun logRecyclerView() {
        var FirebaseRecyclerAdapter = object : FirebaseRecyclerAdapter<Promo, PromoViewHolder>(options){
            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PromoViewHolder {

                var view: View = LayoutInflater.from(context)
                        .inflate(R.layout.diskon_row, parent, false)

                return PromoViewHolder(view)
            }

            override fun onBindViewHolder(holder: PromoViewHolder, position: Int, model: Promo) {
                Picasso.with(context).load(model!!.image).into(holder!!.itemView.rootView.promoImage)
            }

//            override fun populateViewHolder(viewHolder: PromoViewHolder?, model: Promo?, position: Int) { //                //viewHolder??.itemView.userName.setText(model.name) //                Picasso.with(context).load(model!!.image).into(viewHolder!!.itemView.rootView.promoImage) //            }

        }
        mRecyclerView.adapter = FirebaseRecyclerAdapter
    }


    companion object {
        fun newInstance(): HomeFragment = HomeFragment()
    }

    class PromoViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView){

    } }

this is my promo model 这是我的促销模特

package com.fish.isyania.aplikasipemesananreparasi.model

import com.google.firebase.database.IgnoreExtraProperties
@IgnoreExtraProperties
class Promo {

    var name: String = ""
    var image: String = ""
    var diskon: Long = 0

    constructor() {}

    constructor(name: String, image: String, diskon: Long) {
        this.name = name
        this.image = image
        this.diskon = diskon
    }
}

this is my gradle 这是我的礼物

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.fish.isyania.aplikasipemesananreparasi"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:animated-vector-drawable:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.1'

    implementation 'com.google.firebase:firebase-auth:11.8.0'
    implementation 'com.google.firebase:firebase-storage:11.8.0'
    implementation 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.firebaseui:firebase-ui-database:3.1.3'
    implementation 'com.google.android.gms:play-services-auth:11.8.0'

    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.support:support-vector-drawable:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

apply plugin: 'com.google.gms.google-services'

Try to update your gradle Firebase dependencies version 尝试更新您的Gradle Firebase依赖版本

Use 采用

 implementation 'com.firebaseui:firebase-ui-database:3.3.1'

Instead of 代替

  implementation 'com.firebaseui:firebase-ui-database:3.1.3'

Also update all firebase dependencies version 同时更新所有Firebase依赖版本

11.8.0

to

15.0.0

like that 像那样

    implementation 'com.google.firebase:firebase-auth:15.0.0'
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    implementation 'com.google.firebase:firebase-database:15.0.0'

I hope it will work for you !! 我希望它将为您服务!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM