Fragments, Drag & Drop, and Split touch

Fragment definition:

1. A fragment is a portion of an activity
2. We can combine fragments into a single activity and reuse a fragment in more than one activity.
3. A fragment must always be embedded in an activity and the fragment life cycle is directly affected by the host activity.
4. We may also use fragment as an invisible worker for the activity.

Few subclasses of Fragment

1. DialogFragment: Using this class we can create dialogs for an activity and this is an alternative to using dialog helper methods.
2. ListFragment: Displays a list of items that are managed by an adapter and this is similar to ListActivity.
3. PreferenceFragment: Displays a hierarchy of Preference objects as a listand this is similar to PreferenceActivity.

Life cycle of fragment:


Example on fragments:

Activity with two fragments:


Both the fragments are in the main xml file of activity, attribute android:name should be define with the class which extends fragment(fragment class with your requirement).
Fragments without defining in the layout file: In the main activity class we need write bellow code to embed fragments into activity.
//creating a new fragment
Fragment fragment = new TestListFragment();
//Creating FragmentTransaction object which will be used to add, replace, etc.. a fragment in activity.
FragmentTransaction ft = getFragmentManager().beginTransaction();
//Adding a fragment to the layout
ft.add(, fragment, "ListFragment");
//Finally commiting the fragment transaction.

Split motion event

attribute: splitMotionEvents value: true/false
By enabling this attribute for parent layout we can interact with the two childs of the parent.

Drag listener

This is a special functionality provided in honeycomb. Which helps to drag and drop the widgets from one position to another.
Code syntax:
view.setOnDragListener(new View.onDragListener(){
final onDrag(View v, DragEvent event){
return false;