【发布时间】:2020-02-23 17:45:10
【问题描述】:
当我单击回收站视图中的单元格以显示它正忙时,我试图显示进度条。
我有一个片段,加载时它显示进度条没有问题(它只是一个动画条,与进度无关)。
我隐藏了进度条,当我单击回收器适配器中的一个单元格时,我尝试使进度条可见,但无论它给出什么错误,我已经在绑定中尝试过它以及在单击单元格时来自回收器适配器的片段,该功能可以工作,但是当它显示进度条可见时,它会给出错误,
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 不能为空
【问题讨论】:
-
在您的布局中是否设置了进度条?特别是在您的 ViewHolder 布局中
-
-
@beastlyCoder 我在片段的布局文件中有。
-
@OlleEkberg 我刚刚发现并在代码中对其进行了调整,我确实在 bind 函数中尝试了 int ,但是在调用该方法时在片段中尝试了
标签: android kotlin fragment progress-bar android-recyclerview