Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put an activity into a fragment?

I have a ViewPager with 3 pages. In each page, I would like to insert a listview which is populated in seperate classes. Now, I found the simplest method is by inflate layouts which has a fragment in it. Lets say I have 3 pages. In page 1 I inflate a layout with fragment1, in page 2 I inflate a layout with fragment2, and in page 3 I inflate a layout with fragment3. How do I assign activities as the fragments contents? I have been searching through the internet for tutorials but none really fits my needs. Or are there any better way to achieve my goal?

Illustration: enter image description here

Activity 1 2 and 3 are all ListViews. The inflate custom layouts as their itemslayout.

like image 971
borislemke Avatar asked Aug 31 '25 10:08

borislemke


1 Answers

How do I assign activities as the fragments contents?

You don't. Activities hold fragments, not the other way around.

Or are there any better way to achieve my goal?

Use a ListFragment for each page of your ViewPager. Beyond that, you have not explained what your goal is, and therefore it is difficult to assist you further.

like image 84
CommonsWare Avatar answered Sep 03 '25 00:09

CommonsWare