Fragments–applications made modular
The Android SDK 3.0 (Honeycomb) introduced the Fragments API. The Fragments API is basically a set of tools which allows us to create, manage and re-use Chuncks of logic and UI. For example, let’s assume I’m starting to develop an Application, which should be compatible for both Smartphones and Tablet, as well as support both orientation(landscape, portrait). It’s fairly easy to say that the same “lisviews” or forms will be used on both versions in terms of business logic and behavior with some UI adjustments. the fragments API is exactly what we need in order to do it in an elegant manner. let’s check out the following sample: public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); Button btn = (Button) findViewById(R.id.button); btn.setOnClickListener( new OnClickListener() { ...