Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to put a fragment list inside of activity
    text
    copied!<p>I know how to replace a whole activity layout with a fragments list, but how do I nest a fragments list inside of a part of an activity layout?</p> <p><strong>EDIT</strong>: I have attached a picture of what Im trying to achieve at the bottom</p> <p><strong><em>This is what I know how to do:</em></strong></p> <p>I have an actionbar with 3 tabs below it. When a tab has been clicked a feed of fragments comes on screen (like the feed of the FB app)</p> <p><strong><em>This is what I dont know how to do:</em></strong> I have an actionbar Below it I have some content that I want to remain static Below the static content I want to nest a feed like the one described above.</p> <p><strong><em>Here is what I've tried:</em></strong></p> <pre><code>public class MyProfileActivity extends SherlockListFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String[] values = new String[] { "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3", "Samsung Galaxy S3" }; ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(), R.layout.my_profile_feed_custom, R.id.tvProfileFeedItemName, values); setListAdapter(adapter); } </code></pre> <p>And I want to place this inside of here:</p> <pre><code> public class MyProfile extends ActionBarAndSlidingMenu implements OnClickListener{ private TableRow myProfileActionButtonsHolder; private TableRow myProfileStatsHolder; private TableRow myProfileActivityHolder; public MyProfile() { super(R.string.app_name); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.user_profile); myProfileActionButtonsHolder = (TableRow) findViewById(R.id.userProfileActionButtonsHolder); getSupportFragmentManager().beginTransaction().replace(R.id.userProfileActionButtonsHolder, new MyProfileActionButtonsFragment()).commit(); //this one works - it places //two buttons below the user info (it is a single fragment) myProfileStatsHolder = (TableRow) findViewById(R.id.myProfileStatsHolder); getSupportFragmentManager().beginTransaction().replace(R.id.myProfileStatsHolder, new MyProfileUserStatsFragment()).commit(); //this one also works - it places user //activity stats pane below the user info (it is a single fragment) myProfileActivityHolder = (TableRow) findViewById(R.id.myProfileActivityHolder); getSupportFragmentManager().beginTransaction().replace(R.id.myProfileActivityHolder, new MyProfileActivity()).commit(); //this one doesnt work. It doesnt place the //list of fragments below the stats pane. (it is a fragment list) } </code></pre> <p>This is where placing the fragment list works:</p> <p>public class Home extends ActionBarAndSlidingMenu {</p> <pre><code>public Home() { super(R.string.app_name); } //String userEmail; //String reqFrom = ""; CharSequence[] tabsText = {"Items", "People", "Places", }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab itemsFeedTab = actionBar.newTab(); ActionBar.Tab peopleFeedTab = actionBar.newTab(); ActionBar.Tab placesFeedTab = actionBar.newTab(); Fragment itemsFeedFragment = new FeedItems(); Fragment peopleFeedFragment = new FeedPeople(); Fragment placesFeedFragment = new FeedPlaces(); itemsFeedTab.setTabListener(new MyTabsListener(itemsFeedFragment)); peopleFeedTab.setTabListener(new MyTabsListener(peopleFeedFragment)); placesFeedTab.setTabListener(new MyTabsListener(placesFeedFragment)); actionBar.addTab(itemsFeedTab, 0, true); actionBar.addTab(peopleFeedTab, 1, false); actionBar.addTab(placesFeedTab, 2, false); configurationz = new Configurationz(); for(int i = 0; i&lt;actionBar.getTabCount(); i++){ LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.tab_title, null); titleTV = (TextView) customView.findViewById(R.id.action_custom_title); actionBar.getTabAt(i).setCustomView(customView); } class MyTabsListener implements ActionBar.TabListener { public Fragment fragment; public MyTabsListener(Fragment fragment){ this.fragment = fragment; } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub ft.replace(R.id.home, fragment); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { } } </code></pre> <p>And the fragment looks the same way as the fragment in the above example. Here, when I click a tab, it replaces the whole screen contents with a fragment list.</p> <p>In the above example I only need to replace a part of the screen with a fragment list, but I dont know how.</p> <p><img src="https://i.stack.imgur.com/Ldib5.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload