更新对话框片段视图从活动中多次

时间:2019-02-25 09:38:46

标签: android android-fragments

我试图通过对话框片段显示一些进度,但是它只会更新视图一次,之后再也不会更新视图。

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更新这些视图?

0 个答案:

没有答案