单击回收站适配器,Kotlin,Android Studio中的单元格时显示进度栏

问题描述 投票:0回答:1

当我在回收器视图中单击某个单元以显示其繁忙时,我试图显示进度条。

我有一个片段,在加载时它显示进度条没有问题(它只是一个动画条,不与进度链接。

我隐藏了进度条,当我单击回收站适配器中的某个单元格时,我试图使进度条可见,但没有显示错误,我已经在绑定中尝试了它,并在片段中调用了一个函数从回收站适配器中单击单元格时,该功能可以工作,但当它显示进度条为可见时,则会显示错误,>

progressBar不能为空

这是我的代码

在回收站适配器中

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
    when(holder) {
        is HistoryRecyclerAdaptor.HistHolder -> {
            holder.bind(items.get(position))


            holder.itemView.setOnClickListener { v ->




                val pdfN1 = holder.pdf.replace("BBBuxD3Uy/Payments/", "")
                val pdfN = pdfN1.replace(".pdf", "")


                var pdfI = mStorageRef!!.child(usernameGet).child("Payments").child("$pdfN1")


                val localFile = File.createTempFile("$pdfN-", ".pdf")
                pdfI.getFile(localFile).addOnSuccessListener {
                    //            findViewById<PDFView>(R.id.activityMainPdfView).fromAsset(localFile.path).show()

                    val fragment = HistoryFragment()
                    fragment.openFile(holder.itemView.context, localFile.path)

                }.addOnFailureListener {
                    // Handle any errors
                }
            }
        }
    }
}

和片段

fun openFile(context: Context, localPath: String?) { // Create URI
    println("Tony Open file hit")
    progressBar2.visibility = View.VISIBLE
    try {
        val file = File(localPath)
        val uri = FileProvider.getUriForFile(
            context,
            context.applicationContext.packageName.toString() + ".provider", file

        )
        val intent = Intent(Intent.ACTION_VIEW)
        println("Tony Open file hit 2")

        if (file.toString().contains(".pdf")) { // PDF file
            intent.setDataAndType(uri, "application/pdf")
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            context.startActivity(intent)
            println("Tony Open file hit 3")
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

和错误

java.lang.IllegalStateException:progressBar2不能为null

我尝试在回收器视图中单击某个单元以显示其繁忙时显示一个进度条。我有一个片段,在加载时它显示进度栏没有问题(它只是一个动画栏...

android kotlin fragment progress-bar recycler-adapter
1个回答
0
投票

我找到了答案。

© www.soinside.com 2019 - 2024. All rights reserved.