我目前尝试使用Android的 Fabulous筛选器库(Link)制作一个Floating Button
,以打开一个带有动画的Fragment Dialog
。
我想将其用作过滤器片段对话框,允许用户选择日期,然后将所选日期传递回屏幕(我使用片段而不是活动)。
即使我遵循了文档代码,回调似乎也不起作用。
我的问题:
override fun onResult(result: Any?)
时,Fragment Dialog
永远不会被调用/运行,是否执行不正确,所以回调函数永远不会被调用?我的愿望结果:
Fragment Dialog
传递到屏幕(片段)?我的屏幕课程(片段)
class DashboardFragment : Fragment(), AAH_FabulousFragment.Callbacks {
override fun onResult(result: Any?) {
Log.d("k9res", "onResult: " + result.toString());
if (result.toString() == "swiped_down") {
//do something or nothing
} else {
//handle result
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_dashboard, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
floatingActionButton2.setOnClickListener {
val dialogFrag = HistoryFilterFragment.newInstance()
dialogFrag.setParentFab(floatingActionButton2)
dialogFrag.show(this.fragmentManager, dialogFrag.tag)
}
}
}
片段对话框类
class HistoryFilterFragment : AAH_FabulousFragment() {
override fun setupDialog(dialog: Dialog, style: Int) {
val contentView = View.inflate(context, R.layout.fragment_history_filter, null)
val rl_content = contentView.findViewById(R.id.rl_content) as RelativeLayout
contentView.button2.setOnClickListener { closeFilter("closed") }
setAnimationDuration(500)
setPeekHeight(400)
// Callback Function Here
setCallbacks(targetFragment as AAH_FabulousFragment.Callbacks?) //optional; to get back result
setAnimationListener(targetFragment as AAH_FabulousFragment.AnimationListener?) //optional; to get animation callbacks
setViewMain(rl_content)
setMainContentView(contentView)
super.setupDialog(dialog, style)
}
companion object {
fun newInstance(): HistoryFilterFragment {
return HistoryFilterFragment()
}
}
}