Native Adapters in Android

In most cases you won’t have to create your own Adapters from scratch. Android supplies a set of Adapters that can pump data from common data sources (including arrays and Cursors) into the native controls that extend Adapter View Because Adapters are responsible both for supplying the data and for creating the Views that represent … Read more

The Android Widget Toolbox

Android supplies a toolbox of standard Views to help you create your UIs. By using these controls (and modifying or extending them, as necessary), you can simplify your development and provide consistency between applications The following list highlights some of the more familiar toolbox controls: TextView — A standard read-only text label that supports multiline … Read more

Android Fragment Classes

The Android SDK includes a number of Fragment subclasses that encapsulate some of the most common Fragment implementations. Some of the more useful ones are listed here: DialogFragment — A Fragment that you can use to display a floating Dialog over the parent Activity. You can customize the Dialog’s UI and control its visibility directly … Read more

Fragments Without User Interfaces

In most circumstances, Fragments are used to encapsulate modular components of the UI; however, you can also create a Fragment without a UI to provide background behavior that persists across Activity restarts. This is particularly well suited to background tasks that regularly touch the UI or where it’s important to maintain state across Activity restarts … Read more

Interfacing Between Fragments and Activities in Android

Use the getActivity method within any Fragment to return a reference to the Activity within which it’s embedded. This is particularly useful for fi nding the current Context, accessing other Fragments using the Fragment Manager, and finding Views within the Activity’s View hierarchy. TextView textView = (TextView)getActivity().findViewById(R.id.textview); Although it’s possible for Fragments to communicate directly … Read more

Animating Fragment Transactions in Android

To apply one of the default transition animations, use the setTransition method on any Fragment Transaction, passing in one of the FragmentTransaction.TRANSIT_FRAGMENT_* constants. You can also apply custom animations to Fragment Transactions by using the setCustom Animations method. This method accepts two animation XML resources: one for Fragments that are being added to the layout … Read more

Fragment Manager to Find Fragments in Android

To find Fragments within your Activity, use the Fragment Manager’s findFragmentById method. If you have added your Fragment to the Activity layout in XML, you can use the Fragment’s resource identifier: If you’ve added a Fragment using a Fragment Transaction, you should specify the resource identifier of the container View to which you added the … Read more

Fragment Manager in Android

Each Activity includes a Fragment Manager to manage the Fragments it contains. You can access the Fragment Manager using the getFragmentManager method: The Fragment Manager provides the methods used to access the Fragments currently added to the Activity, and to perform Fragment Transaction to add, remove, and replace Fragments Adding Fragments to Activities Adding Fragments … Read more