Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Multiple Fragments in an single activity

I want to develop an android application using Honey Comb 3.0 in which I want to display a list , clicking on any item in a list should display another list beside that list item in the form of Fragment. Can any one provide me sample code in sorting out this issue?

Thanks in Advance,

like image 507
Android_programmer_camera Avatar asked Feb 09 '11 18:02

Android_programmer_camera


People also ask

What is the use of fragments in an activity?

Two fragments in one activity. A fragment represents a portion of user interface in an Activity, and provides a mechanism for creating reusable modules, after being created this module can be embedded within activities.

How to display 2 fragments in the activity in Android Studio?

In Android Studio, Right click on main source set folder, click on New -> Activity -> Empty Activity. Now you have created the base activity. After creating the activity, we need to edit the xml file. In this blog, I’ll show How to display 2 fragments in the activity.

Is it better to use fragments or single activity for UI?

Recently Google have suggested that it’s better to use single activity for your applications. But what if your designer say that one UI should be on fullscreen, while another in simple mode, without drawing over status bar. Then for resolving this issue we will create one more Activity for Fullscreen and one Activity with Fragments for simple UI.

What is a fragment in Java?

The fragment is something like Frame in Html. One Html can contain multiple Frames, and one Activity can include multiple Fragments. Each Fragment can have its own layout XML file, can contain its own view objects and encapsulate its own functionality. It can be reused by any activity.


1 Answers

Have a look at these two blog posts from Google's Reto Meier:

  1. http://blog.radioactiveyak.com/2011/02/android-app-surgery-earthquake-redux.html
  2. http://blog.radioactiveyak.com/2011/02/strategies-for-honeycomb-and-backwards.html

He has lots of code examples in there for handling fragments.

like image 67
Ollie C Avatar answered Sep 24 '22 02:09

Ollie C