-1

I just started working with Fragment. At the moment, I am getting confused here. I chose a platform from Android Studio. There is a list in the left side. What I want to do is that everytime, when I clicked to an item in the list, the contain should be updated.

My problem is that I cannot know when which fragment is loaded everytime when I clicked to an item in the list. Is there any way to know the fragment id. For example, if fragment 1 is load, I will display an imageview, but if fragment 2 is loaded, I will have a checkbox in the main activity.

Cheers,

detno29
  • 2,113
  • 6
  • 19
  • 21

1 Answers1

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 Take a look to this Get the current fragment object

Community
  • 1
  • 1
Tarun Sharma
  • 824
  • 1
  • 11
  • 24