0

I have a 1) MainActivity. 2) Fragment 1 (Listview) 3) Fragment 2 (Listview) 4) Fragment 3 (Textview)

I can successfully launch Fragment 1 when the app is first started. Then, once i click on any listitem on Fragment 1, Fragment 2 is launched. I've handled both these fragments with the following condition in order to differentiate inside my MainActivity

    if (this.getIntent().getExtras()
             == null) {
        fragmentManager.beginTransaction()
                .replace(R.id.restaurantlist, Fragment1).commit();

    } else {


        String id = String.valueOf(getIntent().getExtras().getString(
                "restaurant_id"));
        fragmentManager.beginTransaction()
                .replace(R.id.offerlist, Fragment2).commit();
    }

Now how do i move to Fragment 3 by clicking a list item on Fragment 2? Right now, im also using putEctra AND getExtra "id". For Fragment 2 and Fragment 3. But how do i use it to differentiate inside the above code?

LEE
  • 3,335
  • 8
  • 40
  • 70
  • http://stackoverflow.com/questions/4233873/how-to-get-extra-data-from-intent-in-android using this post i solved my question. :) – LEE Aug 17 '14 at 11:05

1 Answers1

0

Your question is not clear enough for me. If i get you right you have 3 fragments and there is a situation you want to show them all at the same time (e.g. in tablets). If that is not the case don't use fragments at least the way you are using it right now, Instead use another activity because using fragments where there is no need for them only makes your application more complicated.

Any way i suppose you have 3 container in your activity. when app starts add them all! . also add a onItemClike listener to fragment 1, and fragment 2. so when ever a click on item happens you now about that. Now whenever a click happens inform the other fragment to show the relevant item. to do that you only need to define a public method in fragment 2 and fragment 3.

you can also use fragment manager show() and hide() methods to hide your fragment when necessary.

Alireza Ahmadi
  • 5,122
  • 7
  • 40
  • 67
  • Alireza, i appreciate your comment. Actually it was quite simple, and i was thinking the hard way. What i did is created a new Intent. passed unique values from each fragment and received those values inside my activity. Thus i could identify which fragment is giving the call. Problem is solved. :) – LEE Aug 17 '14 at 11:21