另一个函数的自定义对话框的可见性消失布局

Visibilty gone layout of custom dialog from another function

我在 kotlin 片段中有一个自定义对话框,它有 2 个按钮和一个正在运行的进度条 submitSpk()

class RincianPembelianFragment : androidx.fragment.app.Fragment(), BlockingStep {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val v = inflater.inflate(R.layout.fragment_spk_rincian_bayar, container, false)

    //initialize your UI

    return v
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    activity?.supportFragmentManager?.popBackStack(null, androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE)
    setContext(activity!!.applicationContext) 
}
fun submitSpks (){
        val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val builder = AlertDialog.Builder(context!!)

        val dialogView = inflater.inflate(R.layout.activity_signature, null)
        builder.setView(dialogView)
        builder.setTitle("Tanda Tangan Pembeli")
        //builder.show()
        builder.setCancelable(false)
        dialogView.clear.setOnClickListener {
            dialogView.signature_view.clearCanvas()
        }

        dialogView.save.setOnClickListener {
            submitTtd() // or some fuction else
            dialogView.save.visibility = View.INVISIBLE
            dialogView.progressBar.visibility = View.VISIBLE
        }

        builder.setNegativeButton(""){ dialog: DialogInterface?, which: Int ->

        }

        builder.show()

}

fun submitTtd(){
    // here there will be a crud transaction and visible/invisible button save
}
}

我的自定义对话框是这样的

我想从另一个功能中看到按钮保存 dialogView.save.visibility = View.VISIBLE 的可见性,例如 saveTtd() 我怎样才能做到这一点?我试过 但我的对话框无法显示.. 任何人都可以帮助我吗?先谢谢了

dialogView 存储在全局变量中应该可以完成这项工作。
此外,在显示对话框之前调用 AlertDialog.Builder 实例上的 build() 方法:

class RincianPembelianFragment : androidx.fragment.app.Fragment(), BlockingStep {

    private lateinit var dialogView: View

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val v = inflater.inflate(R.layout.fragment_spk_rincian_bayar, container, false)    
        //initialize your dialog view
        dialogView = inflater.inflate(R.layout.activity_signature, null)
        return v
    }
    
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        activity?.supportFragmentManager?.popBackStack(null, androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE)
        setContext(activity!!.applicationContext) 
    }

    fun submitSpks() {
        // Using requireContext() is suggested
        val builder = AlertDialog.Builder(requireContext())
    
        builder.setView(dialogView)
        builder.setTitle("Tanda Tangan Pembeli")
        builder.setCancelable(false)
        dialogView.clear.setOnClickListener {
            dialogView.signature_view.clearCanvas()
        }
    
        dialogView.save.setOnClickListener {
            submitTtd() // or some fuction else
        }
    
        builder.setNegativeButton(""){ dialog: DialogInterface?, which: Int ->
    
        }
    
        // Build the dialog builder before showing it 
        val dialog = builder.build()
        dialog.show()
    }
    
    fun submitTtd(){
        // here there will be a crud transaction and visible/invisible button save
        dialogView.save.visibility = View.INVISIBLE
        dialogView.progressBar.visibility = View.VISIBLE
    }
}