android - 我如何从 Fragment 调用 FragmentManager?科特林
问题描述
我正在构建警报应用程序并尝试打开时间选择器对话框。我需要在关闭后获取时间数据。问题出在.show()
功能上。它在片段中不起作用。它说None of the following functions can be called with the arguments supplied.
我的课
class AlarmPickerDialog : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater?, container:
ViewGroup?, savedInstanceState: Bundle?): View {
var myView = inflater!!.inflate(R.layout.alarm_time_picker, container, false)
return myView
}
}
还有我的调用方法
val alarmDialog = AlarmPickerDialog()
val fm = getActivity()!!.getSupportFragmentManager()
alarmDialog.show(fm, "MyDialog")
也许有更好的方法来获取时间数据?
解决方案
问题:它似乎从而不是AlarmPickerDialog
延伸。android.app.DialogFragment
android.support.v4.app.DialogFragment
解决方案:将代码更改为
// Comment-out this line
// import android.app.DialogFragment
// Add this line
import android.support.v4.app.DialogFragment
class AlarmPickerDialog : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var myView = inflater!!.inflate(R.layout.alarm_time_picker, container, false)
return myView
}
}
推荐阅读
- ios - iOS 开发证书过期对分发配置文件有什么影响?
- python - 如何使用 newick 格式的树字符串 [Python] 正确更新空的 ete3.Tree 对象?
- unity3d-editor - 为统一 3d 编辑器编写代码并加载 json 数据文件,但在统一编辑器中出现错误
- c# - 如何首先在数据库中自动应用查询类型(Scaffold-DbContext)而不会在重新生成时丢失它们?
- sql - SQL Server - 如果是新行,则插入行;如果存在则更新
- python - 优化大型级联文件/循环的脚本以从文件列表中丢弃有缺陷的项目
- php - laravel php 工匠迁移
- rest - 通过未格式化的电话号码搜索 Microsoft Dynamics Rest Api 记录
- validation - 在架构中允许未知键但经过验证的值
- android - 在列表视图中仔细检查 Android Studio