我正在从片段中使用BottomSheet对话框。我想在底表关闭后重新加载片段数据。
我正在尝试通过在onResume方法中添加重新加载代码。但这不起作用。
这里是我的BottomSheet对话框代码。
class LoopResponseDialogueFragment : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.fragment_loop_response_dialog, container, false)!!
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
var progressDialog = ProgressDialog(context)
acceptButton.setOnClickListener {
priyoLoopService.sendLoopResponse(LoopActionRequest(user.id, "accept"))
.enqueue(object : Callback<GenericLoopResponse> {
override fun onFailure(call: Call<GenericLoopResponse>, t: Throwable) {
}
override fun onResponse(
call: Call<GenericLoopResponse>,
response: Response<GenericLoopResponse>
) {
dismiss()
}
})
}
}
答案 0 :(得分:0)
您可以在LoopResponseDialogueFragment类中创建一个接口,并在片段中使用它。覆盖onDismiss()和onCancel()函数并调用接口函数。
LoopResponseDialogueFragment代码:
class LoopResponseDialogueFragment : BottomSheetDialogFragment() {
private lateinit var onBottomSheetCloseListener:OnBottomSheetCloseListener
interface OnBottomSheetCloseListener{
fun onBottomSheetClose()
}
fun setOnBottomSheetCloseListener(listener:OnBottomSheetCloseListener) {
onBottomSheetCloseListener = listener
}
// rest of the code
override fun onDismiss(dialog: DialogInterface)
{
super.dismiss(dialog)
listener.onBottomSheetClose()
}
}
现在在片段中调用show方法之前,请调用setOnBottomSheetCloseListener()
在您的片段中:
dialog.setOnBottomSheetCloseListener(object: OnBottomSheetCloseListener{
override fun onBottomSheetClose()
{
//refresh your data here
}
})
您可以添加代码以刷新onBottomSheetClose方法中的片段数据。