【问题标题】:How to update activity on fragments in Android [closed]如何在 Android 中更新片段的活动 [关闭]
【发布时间】:2014-09-06 03:05:21
【问题描述】:

我刚开始使用 Fragment。目前,我在这里感到困惑。我从 Android Studio 中选择了一个平台。左侧有一个列表。我想要做的是,每次当我点击列表中的一个项目时,都应该更新包含。

我的问题是每次单击列表中的项目时,我都不知道何时加载哪个片段。有没有办法知道片段ID。例如,如果片段 1 已加载,我将显示一个 imageview,但如果片段 2 已加载,我将在主 Activity 中有一个复选框。

干杯,

【问题讨论】:

    标签: android android-fragments


    【解决方案1】:
    In your kind of situations, I mostly Follow a simple way
    
    1.Use Different Framlayouts(Container of Fragment). In your Case,1. FrameLayout For List and 2. Framlayout for its content. 
    2. ListView item Click Make Content Fragment View (Framlayout) Visible. 
    3. Attached Fragment at onCreate or onStart. but make Content invisible or Visible as your requirement.
    

    you can know more about Fragment(how to attach and detach Fragment to an activity).

    About your Sceond Problem ,follow these solutions 
    

    Android - Set fragment id 看看这个Get the current fragment object

    【讨论】:

    • 非常感谢,我试试看效果如何。
    猜你喜欢
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 2014-12-10
    • 2019-07-29
    相关资源
    最近更新 更多