使用 firebase 未显示 Recycler View - kotlin

如何解决使用 firebase 未显示 Recycler View - kotlin

我正在尝试从 firebase 获取数据并在 recyclerview 中使用

我没有将 xml 代码与此代码一起放置,因为我的 xml 是 100% 的。我认为我的 KT 有一些错误,所以我只上传 KT。

FireBase 中的数据:

    {
  "movielist" : {
    "01" : {
      "director" : "Srinu Vaitla","poster" : "gs://mr-mahesh-10f6d.appspot.com/Dookudu_HQ_posters_mahesh_babu_birt.jpg","rating" : "gs://mr-mahesh-10f6d.appspot.com/rating.png","title" : "Dookudu","year" : 2020
    },"02" : {
      "director" : "Srinu Vaitla","year" : 2020
    }
  }
}

主屏幕活动:

package com.example.maheshbabu

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.firebase.ui.database.FirebaseRecyclerOptions
import com.google.firebase.database.FirebaseDatabase
import kotlinx.android.synthetic.main.layout_main_screen.*

class MainScreenActivity : AppCompatActivity(),RecyclerViewAdapter.OnItemListener {

    private var adapter: RecyclerViewAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_main_screen)
        recyclerView.layoutManager = LinearLayoutManager(this)
        recyclerView.setHasFixedSize(true)
        val options: FirebaseRecyclerOptions<Holding?> = FirebaseRecyclerOptions.Builder<Holding>()
            .setQuery(
                FirebaseDatabase.getInstance().reference.child("movielist"),Holding::class.java
            )
            .build()

        adapter = RecyclerViewAdapter(options,this,this)
        recyclerView.adapter = adapter
    }

    override fun onStart() {
        super.onStart()
        adapter!!.startListening()
    }

    override fun onStop() {
        super.onStop()
        adapter!!.stopListening()
    }

    override fun onItemClick(movieName: Holding,position: Int) {
        Toast.makeText(this,movieName.title,Toast.LENGTH_SHORT).show()

        intent = Intent(this,InfoScreenActivity::class.java)
//        intent.putExtra("Website",itemView.name.toString())
//        intent.putExtra("Web",position.toString())
        startActivity(intent)
    }

}

回收器视图适配器:

package com.example.maheshbabu

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.firebase.ui.database.FirebaseRecyclerAdapter
import com.firebase.ui.database.FirebaseRecyclerOptions
import com.google.android.material.imageview.ShapeableImageView
import kotlinx.android.synthetic.main.layout_main_screen_recylerview_list.view.*


internal class RecyclerViewAdapter(
    options: FirebaseRecyclerOptions<Holding?>,var clickListener: OnItemListener,private val context: Context
) :
    FirebaseRecyclerAdapter<Holding?,RecyclerViewAdapter.MyViewHolder?>(options) {

    override fun onBindViewHolder(holder: MyViewHolder,position: Int,holding: Holding) {
        holder.movieName?.text = holding.title
        holder.moviePoster?.context?.let {
            Glide.with(it).load(holding.poster).into(holder.moviePoster!!)
        }
        holder.movieDirector?.text = holding.director
        holder.movieYear?.text = holding.year
        holder.movieRating?.context?.let {
            Glide.with(it).load(holding.rating).into(holder.movieRating!!)
        }
    }

    internal inner class MyViewHolder(itemView: View) :
        RecyclerView.ViewHolder(itemView) {
        var movieName: TextView? = itemView.title
        var moviePoster: ShapeableImageView? = itemView.poster
        var movieDirector: TextView? = itemView.director
        var movieYear: TextView? = itemView.year
        var movieRating: ImageView? = itemView.rating
        fun initialize(holderList: Holding,action: OnItemListener) {
            itemView.setOnClickListener {
                action.onItemClick(holderList,adapterPosition)
            }
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup,viewType: Int): MyViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.layout_main_screen_recylerview_list,parent,false)
        return MyViewHolder(view)
    }


    interface OnItemListener {
        fun onItemClick(movieName: Holding,position: Int)
    }
}

持有人:

package com.example.maheshbabu

class Holding(
    var title: String?,var poster: String?,var director: String?,var year: String?,var rating: String?
) 

日志猫:

    2021-03-22 07:47:07.453 28773-28773/? I/mple.maheshbab: Late-enabling -Xcheck:jni
2021-03-22 07:47:07.672 28773-28773/com.example.maheshbabu I/Perf: Connecting to perf service.
2021-03-22 07:47:07.689 28773-28773/com.example.maheshbabu W/ComponentDiscovery: Class com.google.firebase.dynamicloading.DynamicLoadingRegistrar is not an found.
2021-03-22 07:47:07.699 28773-28773/com.example.maheshbabu I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2021-03-22 07:47:07.700 28773-28773/com.example.maheshbabu I/FirebaseInitProvider: FirebaseApp initialization successful
2021-03-22 07:47:07.768 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist,reflection)
2021-03-22 07:47:07.770 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist,reflection)
2021-03-22 07:47:07.782 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (light greylist,reflection)
2021-03-22 07:47:07.783 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist,reflection)
2021-03-22 07:47:07.783 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist,reflection)
2021-03-22 07:47:07.783 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (light greylist,reflection)
2021-03-22 07:47:07.783 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (light greylist,reflection)
2021-03-22 07:47:07.783 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist,reflection)
2021-03-22 07:47:07.813 28773-28803/com.example.maheshbabu D/NetworkSecurityConfig: No Network Security Config specified,using platform default
2021-03-22 07:47:07.869 28773-28805/com.example.maheshbabu I/Adreno: QUALCOMM build                   : 6774a42,I60e4284429
    Build Date                       : 09/17/20
    OpenGL ES Shader Compiler Version: EV031.25.03.01
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.7.2.R1.09.00.00.442.049
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
2021-03-22 07:47:07.869 28773-28805/com.example.maheshbabu I/Adreno: Build Config                     : S L 6.0.7 AArch64
2021-03-22 07:47:07.875 28773-28805/com.example.maheshbabu I/Adreno: PFP: 0x005ff113,ME: 0x005ff066
2021-03-22 07:47:07.880 28773-28805/com.example.maheshbabu I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-03-22 07:47:07.880 28773-28805/com.example.maheshbabu I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2021-03-22 07:47:07.881 28773-28805/com.example.maheshbabu I/OpenGLRenderer: Initialized EGL,version 1.4
2021-03-22 07:47:07.882 28773-28805/com.example.maheshbabu D/OpenGLRenderer: Swap behavior 2
2021-03-22 07:47:07.885 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden field Landroid/os/Trace;->TRACE_TAG_APP:J (light greylist,reflection)
2021-03-22 07:47:07.886 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (light greylist,reflection)
2021-03-22 07:47:07.886 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (light greylist,reflection)
2021-03-22 07:47:07.886 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (light greylist,reflection)
2021-03-22 07:47:07.886 28773-28773/com.example.maheshbabu W/mple.maheshbab: Accessing hidden method Landroid/os/Trace;->traceCounter(JLjava/lang/String;I)V (light greylist,reflection)

App is Running,No Error's also

解决方法

现已修复

“年”:2020 到“年”:“2020”

"poster" : "gs://mr-mahesh..." 到图片网址

recyclerView.setHasFixedSize(true) 被移除

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-