Unit -04 Using Built-in View Container Classes



Lesson Plan: Unit - 04
Subject: P15A2AAD - Android Application Development
Topic of Study: Using Built-in View Container Classes
Grade/Level: Master of Computer Applications
Objective: To demonstrate different built-in View Container Classes
Time Allotment: 55 Minutes


  • Using Built-in View Container Classes
    • Layouts are not the only controls that can contain other View objects.
    • These View objects encapsulate other, simpler View types and give the user some interactive ability to browse the child View objects in a standard fashion.
    • The types of ViewGroup containers built-in to the Android SDK framework include
      • Lists, grids, and galleries
      • Switchers with ViewFlipper, ImageSwitcher, and TextSwitcher
      • Tabs with TabHost and TabControl
      • Scrolling with ScrollView and HorizontalScrollView
      • Hiding and showing content with the SlidingDrawer
    • Using Data-Driven Containers:
      • Some of the View container controls are designed for displaying repetitive View objects in a particular way. 
      • Exa.
        • ListView: Contains a vertically scrolling, horizontally filled list of View objects, each of which typically contains a row of data; the user can choose an item to perform some action upon.
        • GridView: Contains a grid of View objects, with a specific number of columns; this container is often used with image icons; the user can choose an item to perform some action upon.
        • GalleryView: Contains a horizontally scrolling list of View objects, also often used with image icons; the user can select an item to perform some action upon.
    • Adapter View:
      • These containers are all types of AdapterView controls.
      • An AdapterView control contains a set of child View controls to display data from some data source.
      • An Adapter generates these child View controls from a data source.
      • An Adapter reads data from some data source and provides a View object based on some rules, depending on the type of Adapter used.
    • Types of Adapter:
      • Adapter classes are the CursorAdapter and the ArrayAdapter.
      • The CursorAdapter gathers data from a Cursor, whereas the ArrayAdapter gathers data from an array.
      • A CursorAdapter is a good choice to use when using data from a database.
      • The ArrayAdapter is a good choice to use when there is only a single column of data or when the data comes from a resource array.
    • Exa. of Design
    • Exa. of Output
    • Step 01 : Demo of List View
    • Step 02 : Demo of List View
  • Using List Activity:
    • The ListView control is commonly used for full-screen menus or lists of items from which a user selects.
    • As such, you might consider using ListActivity as the base class for such screens. 
    • Using the ListActivity can simplify these types of screens.
    • First, to handle item events, you now need to provide an implementation in your ListActivity.
    • For instance, the equivalent of onListItemClickListener is to implement the onListItemClick() method within your ListActivity
    • Second, to assign an Adapter, you need a call to the setListAdapter() method.
    • Exa. of Design
    • Exa. of Output
    • Step 01: Demo of List Activity
    • Step 02: Demo of List Activity
    • Step 03: Demo of List Activity
  • Organizing Screens with Tabs:
    • The Android SDK has a flexible way to provide a tab interface to the user. 
    • Much like ListView and ListActivity.
    • There are two ways to create tabbing on the Android platform.
    • You can either use the TabActivity, which simplifies a screen with tabs, or you can create your own tabbed screens from scratch. 
    • Both methods rely on the TabHost control.
    • Tab Host:
      • Android TabHost  provides a nice way to present multiple thing on a Single Screen. 
      • These  things are presented by Tabs.
      • In order to use tabs we need to set 2 things to Tab…
        • Tab Indicator : Text to show on Tab,  done by  setIndicator("Tab Name");
        • TAB Content: The activity that will be opened when user selects/clicks particular tab, done by  setContent(activityObject);
    • Exa.
      • Step 01 : Select the Project.
      • Step 02: Add Tabhost to Activity.
      • Step 03: Just drag and drop that you want on tabs. It will create no of tabs as per controls.
      • Step 04: Modify in Java file.
  • Customized Tabs:
    • Step 01: Create Project & Add TabHost control & add id=“@android:id/tabhost” & remove 3 tabs.
    • Step 02: extends the activity…
      • Exa.
    • Step 03: Write a code & create a empty activities…
      • Exa.
    • Step 04: appends the tab…
      • Exa.
    • Step 05: Run your code.
  • Exploring Other View Containers
    • SlidingDrawer: 
      • This control includes two parts: a handle and a container view. 
      • The user drags the handle open and the internal contents are shown; then the user can drag the handle shut and the content disappears. 
      • The SlidingDrawer can be used horizontally or vertically and is always used from within a layout representing the larger screen.
      • Exa.
      • Step 01: Design in XML
      • Step 02: Write Code in .java
  • View Switcher:
    • In Android, ViewSwitcher is a sub class of ViewAnimator that is used for switching between views. 
    • It is an element of transition widget which helps us to add transitions on the views. 
    • It is mainly useful to animate a view on screen. 
    • ViewSwitcher switches smoothly between two views (i.e. TextView, ImageView or any layout) and thus provides a way of transitioning from one view to another through appropriate animations. 
    • You can create views for a ViewSwitcher widget either using a factory or by adding them on your own.
    • Step 01 : Drag the ViewSwitcher in xml.
      • Exa
    • Step 02 : write a code in .java file
      • Exa.
    • Step 02 : write a code in .java file
      • Exa.

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form