Android Fragments 检测底部工作表对话框片段在基础片段上关闭

cedebl8k  于 2023-08-06  发布在  Android
关注(0)|答案(3)|浏览(148)

我有fragment,它包含recycleview和list。在fragment中,我正在调用另一个底层工作表dialog fragment,我想知道当我关闭底层工作表dialog fragment时如何刷新基本片段列表。
我在基本片段中尝试了onpauseonresume方法。请帮我解决这个问题。

ukxgm1gy

ukxgm1gy1#

此方法在对话框碎片被消除时触发。重写对话框片段中的方法。

@Override
public void onDismiss(@NonNull DialogInterface dialog) {
    super.onDismiss(dialog);
    // use interface to callback method in base fragment
}

字符串

insrf1ej

insrf1ej2#

我不确定,但我试过破解密码,成功了。

@Override
public void dismiss() {
    super.dismiss();
    ((MyActivity)context).myRefreshFunction();// 
}

字符串

gupuwyp2

gupuwyp23#

调用BottomSheetDialogFragment
单击事件打开按钮SheetDialgFragment

class GuestFragment : Fragment(){
        .
        .
        .
        .

        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
            binding.tvInfo.setOnClickListener {
                val dialogFragment = BottomSheetDogGiveReviewFragment(requireContext(),data.ratingData,data)
                // call back method
                dialogFragment.setOnBottomSheetDismissListener  {
                    resumeFragment()
                }
                dialogFragment.show(parentFragmentManager, "My  Fragment")
            }

        }

    }

字符串
在底部工作表对话框片段中

class BottomSheetDogGiveReviewFragment(context: Context) : BottomSheetDialogFragment() {
        //this is binding xml file
        private var _binding : FragmentBottomSheetDogGiveReviewBinding?=null
        private val binding get() = _binding!!
        
        //make this listener through call over Fragment mehod
        private var onDismissListener: (() -> Unit)? = null
        fun setOnBottomSheetDismissListener(listener: () -> Unit) {
            onDismissListener = listener
        }
        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            // Inflate the layout for this fragment
            _binding = FragmentBottomSheetDogGiveReviewBinding.inflate(inflater, container, false)
            val view = binding.root
            return view
        }
        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)

            //button click
            binding.tvSubmit.setOnClickListener {
                ....
                ..
                dialog!!.dismiss()
                onDismissListener?.invoke()
            }
        }

        //dialog them
        override fun getTheme(): Int {
            return  R.style.CustomBottomSheetDialog
        }
    }


// buttom sheet dialog them //在themes.xml文件中添加主题

//buttom sheet dialog style
        <style name="CustomBottomSheetDialog" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
            <item name="bottomSheetStyle">@style/CustomBottomSheet</item>
        </style>

相关问题