如何更新Android中的片段活动

时间:2014-09-06 03:05:22

标签: android android-fragments

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

我的问题是,当我点击列表中的某个项目时,我无法知道每次加载哪个片段。有没有办法知道片段ID。例如,如果片段1加载,我将显示一个imageview,但如果加载片段2,我将在主活动中有一个复选框。

干杯,

1 个答案:

答案 0 :(得分: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