0% found this document useful (0 votes)
12 views9 pages

M4

The document provides an overview of common views in Android, including TextView, Button, ImageView, EditText, CheckBox, and Spinner, each with their properties and examples. It also explains the concept of Fragments, their lifecycle methods, and their benefits for UI design. Additionally, it covers the use of dialogs, checking internet connectivity programmatically, and implementing multimedia features like video and audio playback in Android applications.

Uploaded by

abhishes39561
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

M4

The document provides an overview of common views in Android, including TextView, Button, ImageView, EditText, CheckBox, and Spinner, each with their properties and examples. It also explains the concept of Fragments, their lifecycle methods, and their benefits for UI design. Additionally, it covers the use of dialogs, checking internet connectivity programmatically, and implementing multimedia features like video and audio playback in Android applications.

Uploaded by

abhishes39561
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Views in Android: (With an example for each, explain common views in Android.

)
Views are instances of the View class, and all UI components in Android, such as buttons, text fields, and image views, are
subclasses of the View class. Views handle the display of content and interaction with the user, and they can be laid out in
various ways to build the interface.
Types of Views in Android:
1. TextView:
o A TextView is used to display text to the user. It can be used for showing simple text, styled text, or even
links.
o Common properties: setText(), setTextColor(), setTextSize(), setTypeface().
o Example: A label or a heading in the UI.

2. Button:
o A Button is a clickable UI element that the user can interact with. It is often used to trigger actions, such as
submitting a form or opening a new activity.
o Common properties: setText(), setOnClickListener().
o Example: A button to submit a form or navigate to another screen.

3. ImageView:
o An ImageView is used to display images. It can show images from resources, files, or even a URL.
o Common properties: setImageResource(), setImageURI(), setImageBitmap().
o Example: Displaying a logo or picture.
4. EditText:
o An EditText is a specialized subclass of TextView that allows users to input text. It's typically used for fields
like username, password, email, etc.
o Common properties: setHint(), setText(), setInputType(), setTextColor().
o Example: A text input field for a user to enter information.

5. CheckBox:
o A CheckBox allows the user to select or deselect an option. It is used when the user can choose one or
more options in a set.
o Common properties: setChecked(), setOnCheckedChangeListener().
o Example: A form with checkboxes for selecting preferences.

6. Spinner:
o A Spinner provides a drop-down list to allow users to select from a list of options. It is similar to a
dropdown menu.
o Common properties: setAdapter(), setOnItemSelectedListener().
o Example: A drop-down list for selecting a country or city.
Define fragment. Explain the life cycle of fragment.
A Fragment in Android is a modular section of an activity. It represents a part of the user interface or behavior in an
activity.
A fragment has its own layout, logic, and lifecycle, but it must be hosted within an activity. Fragments allow for more
flexible UI designs, especially for devices with larger screens, such as tablets, where you can display multiple fragments
at once.
A fragment is useful for:
• Reusing UI components and logic.
• Creating flexible layouts for different screen sizes.
• Managing complex UI behaviors by breaking down the activity into smaller reusable components.

1. onAttach():- called when fragment has attached to the activity


2. onCreate():- called after attaching the fragment to the host activity
3. onCreateView(): -called by the fragment for drawing the user interface
4. onViewCreated(): – This method is called after the view has been created by the onCreateView()
5. onActivityCreated(): It is used to indicate that the host activity has been created
6. onStart():- called when the user interface is visible to the user
7. onResume():- called when the app user can interact with the user interface of the application
8. onPause(): – This method is called when the user is moving to the next fragment or moving back to another
fragment
9. onStop(): – called after the onPause() method
10. onDestroyView():-It is called when the view created by the onCreateView() method has been destroyed or
removed
11. onDestroy(): – It is called to completely remove the fragmented state and its resources from the host activity.
12. onDetach():-It is called after the onDestroy() method to notify that the fragment within the host activity has been
detached.
Develop a mobile application to create a list of programming subjects using spinner view and display the item selected
by the user.
What is the use of Data Picker dialog? Demonstrate with an example how it is handled in Android.
What Are Dialogs?
o We usually create a new activity or screen for interacting with users, but when we want only a little information, or
want to display an essential message, dialogs are preferred.
o Dialogs are also used to guide users in providing requested information, confirming certain actions, and displaying
warnings or error messages. The following is an outline of different dialog window types provided by the Android
SDK:

• Dialog—The basic class for all dialog types.


• AlertDialog—A dialog with one, two, or three Button controls.
• CharacterPickerDialog—A dialog that enables you to select an accented character associated with a regular character
source.
• DatePickerDialog—A dialog that enables you to set and select a date with a DatePicker control.
• ProgressDialog—A dialog that displays a ProgressBar control showing the progress of a designated operation.
• TimePickerDialog—A dialog that enables you to set and select a time with a TimePicker control.

o In Android, Dialog Boxes are used to display messages, ask for input, or perform actions without leaving the current
screen. There are different types of dialogs, such as AlertDialog, DatePickerDialog, and TimePickerDialog.
o AlertDialog: The most commonly used dialog for displaying alerts or prompts. You can create custom layouts or
include buttons for user responses (e.g., OK, Cancel).
Explain how to check internet connection in Android programmatically.
Steps to Check Internet Connection Programmatically
1. Check Network Availability:
o Use the ConnectivityManager class to get information about the device’s network connectivity.
o Check if there is a network connection available (either Wi-Fi or mobile data).
2. Check Network Type:
o If a connection is available, you can also check whether it is Wi-Fi or mobile data, or if it has internet
access (e.g., via HTTP request).
Allow Permission.
How multimedia can be implemented in Android? Explain
1. Playing Video in Android:
To play video in an Android app, you typically use the VideoView component or MediaPlayer.
• Using VideoView: VideoView simplifies video playback, allowing you to load and play video from local or online
sources.
Example:

2. Playing Audio in Android:


For audio playback, the MediaPlayer class is commonly used. It allows playing sound from files or streams (local/remote).
• Example:

3. Capturing Media in Android:


Android allows capturing both images and video through the camera and audio through the microphone.
• Capturing Image/Video: Use an intent with MediaStore.ACTION_IMAGE_CAPTURE for images or
MediaStore.ACTION_VIDEO_CAPTURE for videos.
Example (capturing image):
Illustrate with an example how to play video in an android application

You might also like