我试图通过对话框片段显示一些进度,但是它只会更新视图一次,之后再也不会更新视图。
ProgressDialogFragment.kt
class ProgressDialogFragment: DialogFragment(){
private var pFileSize: TextView? = null
private var pDownloaded: TextView? = null
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val divsStr = arguments?.getString("divs")
val id = arguments?.getInt("id")
val layoutName = arguments?.getString("layout_name")
val parent: ViewGroup? = null
val inflater = activity!!.layoutInflater
val builder = AlertDialog.Builder(context!!)
val view = inflater.inflate(R.layout.dialog_progress, parent, false)
pFileSize = view.findViewById(R.id.fileSize)
pDownloaded = view.findViewById(R.id.downloaded)
builder.setView(view)
return builder.create()
}
fun updateFileSize(fileSize: String) {
pFileSize?.text = fileSize
}
fun updateDownloaded(downloaded: String) {
pDownloaded?.text = downloaded
}
}
在MainActivity
中,从BroadcastReceiver
调用的那些更新方法。我检查了该方法是否正确调用,但是一旦第一次更新,就再也不会更新。有什么方法可以从MainActivity
更新这些视图?