简体   繁体   English

无法从活动移动到片段

[英]Unable to move from activity to fragment

How to move from activity to fragment on button click?如何在单击按钮时从活动移动到片段?

private fun onClickListener() {
            profileImageView.setOnClickListener {
                val i = Intent(this, ProfileFragment::class.java)
                startActivity(i)
            }
}

在这里输入代码

You can't.你不能。 You can either move from activity to activity or fragment to fragment.您可以从一个活动移动到另一个活动,也可以从一个片段移动到另一个片段。 In the first case you can use the code you have implemented with在第一种情况下,您可以使用已实现的代码

private fun onClickListener() {
        profileImageView.setOnClickListener {
            val i = Intent(this, SecondActivityWhatever::class.java)
            startActivity(i)
        }

} }

otherwise you need to implement Navigation Component in order to move from fragment to fragment.否则你需要实现导航组件才能从一个片段移动到另一个片段。

(Another option in your specific case would be using a Custom Fragment Dialog to show the profile) (您的特定情况下的另一个选项是使用自定义片段对话框来显示配置文件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过在Volley Library中使用Intent,无法从片段移动下一个Activity - Unable to move on next Activity from fragment by using Intent in Volley Library 如何从onActivityResult从Activity移到片段 - How to move from Activity to Fragment from onActivityResult 单击按钮时从“活动”移动到“片段” - Move from Activity to Fragment when button clicked 如何在 ViewPage 中从 Activity 移动到 Fragment? 未找到片段 ID 的视图 - How to move from Activity to Fragment in ViewPage? No view found for id for fragment 无法从主要活动加载片段 - Unable to Load Fragment from Main Activity 无法将片段加载到活动中 - Unable to load fragment into activity 从 Fragment 移动到 Activity 导致 android.os.TransactionTooLargeException - Move from Fragment to Activity Causes android.os.TransactionTooLargeException 如何从导航抽屉的片段移动到 Android Studio 上的活动? - How to move from a fragment of a navigation drawer to an Activity on Android Studio? 如何从 1 个 recyclerview 片段移动到它自己的活动? - How to move from 1 recyclerview fragment to its own activity? 单击按钮时从 1 Activity 移动到特定片段。 - Move from 1 Activity to specific fragment on button click.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM