2

It is my first time using android fragment. I am following this tutorial to implement a fragment.

Everything is fine with this tutorial, I successfully get the result like below:

enter image description here

In the tutorial, the DetailsFragment simply shows a TextView containing the text of the currently selected item. That's the right part shows just some texts.

My question is how to show different activities on the right side instead of text views.

What I mean is illustrated in the following image, for example, the area of "1" in the image is an activity. How to show different activities when a list item on the left hand side has selected?

enter image description here

Mellon
  • 37,586
  • 78
  • 186
  • 264

2 Answers2

1

You do not show an activity, you show a fragment. Implement the Fragment class instead of the Activity class. Then you build your View just as you would in an Activity. Remember that for instances when you need access to an activity the Fragment class has the convenient getActivity() method.

Mark Gjøl
  • 1,845
  • 12
  • 21
0

Use FragmentManager.beginTransaction() to start FragmentTransaction. With that operation you can hide and show new Fragments. It is also managed with the android history stack.

https://developer.android.com/reference/android/app/FragmentManager.html#beginTransaction() https://developer.android.com/reference/android/app/FragmentTransaction.html

And here is some code: Android Honeycomb: How to change Fragments in a FrameLayout, without re-creating them?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ludwigm
  • 3,363
  • 3
  • 28
  • 36