How to show different Activities in Fragment imple

2019-05-23 04:21发布

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

2条回答
唯我独甜
2楼-- · 2019-05-23 04:47

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?

查看更多
该账号已被封号
3楼-- · 2019-05-23 04:56

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.

查看更多
登录 后发表回答