0% found this document useful (0 votes)
16 views19 pages

Nis Assignment

The document provides an overview of Android installation and configuration, detailing essential components such as the Java JDK, Android SDK, and Android Development Tools (ADT). It explains the functionality of emulators, Android Virtual Devices (AVDs), and the Dalvik Virtual Machine (DVM), along with UI components and design principles for Android applications. Additionally, it covers various UI elements like TextView, EditText, and Button, as well as how to implement features like Toast notifications and Date & Time Pickers.

Uploaded by

sad14042006
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)
16 views19 pages

Nis Assignment

The document provides an overview of Android installation and configuration, detailing essential components such as the Java JDK, Android SDK, and Android Development Tools (ADT). It explains the functionality of emulators, Android Virtual Devices (AVDs), and the Dalvik Virtual Machine (DVM), along with UI components and design principles for Android applications. Additionally, it covers various UI elements like TextView, EditText, and Button, as well as how to implement features like Toast notifications and Date & Time Pickers.

Uploaded by

sad14042006
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/ 19

Unit 2: Installation & Configuration of Android

1. Explain : Java Jdk & Android sdk

Java JDK

⎯ The Java Development Kit (JDK) is a software development environment used for

developing Java applications and applets.

⎯ It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a

compiler (javac), an archiver (jar), a documentation generator (javadoc) and other

tools needed in Java development.

Android SDK

⎯ Android development starts with the Android SDK (Software Development Kit).

⎯ It is a software development kit that enables developers to create applications for

the Android platform.

The Android SDK includes the following:

• Debugger

• Libraries

• Emulator

• Relevant documentation for the Android application program interfaces (APIs)

• Sample source code

• Tutorials

2. Explain ADT

Android Development Tools (ADT) is a plugin that is designed to give you a powerful, integrated
environment in which to build Android applications.

ADT allows you to quickly set up new Android projects, create an application UI, add packages based
on the Android Framework API, debug your applications using the Android SDK tools, and even
export signed (or unsigned) .apk files in order to distribute your application.

Developing with ADT is highly recommended and is the fastest way to get started. With the guided
project setup it provides, as well as tools integration, custom XML editors, and debug output pane,
ADT gives you an incredible boost in developing Android applications.
3. Define Emulator

Emulators

⎯ The Android Emulator simulates Android devices on your computer so that you can test

your application on a variety of devices and Android API levels without needing to have

each physical device.

⎯ The emulator provides almost all of the capabilities of a real Android device. You can

simulate incoming phone calls and text messages, specify the location of the device,

simulate different network speeds, simulate rotation and other hardware sensors, access

the Google Play Store, and much more.

4. What is AVD ? How to add / Configure AVD in android studio

Android Virtual Devices (AVDs)

⎯ An Android Virtual Device (AVD) is a configuration that defines the characteristics of an

Android phone, tablet, Wear OS, Android TV, or Automotive OS device that you want to

simulate in the Android Emulator.

2. Click Create Virtual Device, at the bottom of the AVD Manager dialog.

3. The Select Hardware page appears.

4. Select a hardware profile, and then click Next.

If you don't see the hardware profile you want, you can create or import a hardware profile.

The System Image page appears.

5. Explain DVM with diagram

2.5 Dalvik Virtual Machine (DVM)

⎯ As we know the modern JVM is high performance and provides excellent memory

management. But it needs to be optimized for low-powered handheld devices as well.

⎯ The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile

devices. It optimizes the virtual machine for memory, battery life and performance.

⎯ //Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.
⎯ The Dex compiler converts the class files into the .dex file that run on the Dalvik VM.

Multiple class files are converted into one dex file.

6. Difference between JVM & DVM

7. Write steps to install & Configure to android studio.


Unit 3: UI Components & Design

1. Draw / list Directory structure of an android application

2. Explain fundamental of UI Design.

⎯ View

• Simplest building block of the user interface.

• Represents a single UI element on the screen.

• Examples:

o TextView: Displays text.

o Button: Allows user interaction.

o ImageView: Displays images.


o EditText: Enables text input.

⎯ ViewGroup

• Container that holds and organizes other Views (or even other ViewGroups).

• Defines the layout and positioning of its child Views.

• Examples:

o LinearLayout: Arranges Views in a single direction (horizontal or vertical).

o RelativeLayout: Positions Views relative to each other or the parent.

o TableLayout: Provides flexible and efficient layout creation.

o FrameLayout: Stacks Views on top of each other.

⎯ Fragment

• Reusable UI component that can be embedded within an Activity.

• Like a mini-Activity with its own layout and behavior.

• Benefits:

o Modularity: Break down complex UIs into smaller, manageable parts.

o Reusability: Use the same Fragment in multiple Activities.

o Adaptability: Easily adapt UI for different screen sizes (phones vs. tablets).

⎯ Activity

• The single, top-level component of an Android application.

• Represents a single screen with a user interface.

• Responsible for:

o Creating and managing the user interface.

o Handling user interactions (e.g., button clicks, screen rotations).

o Interacting with other components (e.g., Services, Broadcast Receivers).

3. Explain (Attributes , program to add components for demonstration)

Linear Layout
⎯ Key Attributes:

o android:orientation:

▪ horizontal: Arranges views from left to right.

▪ vertical: Arranges views from top to bottom.

⎯ Example

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button 1" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button 2" />

</LinearLayout>

Relative Layout

⎯ Key Attributes:

layout_alignParentLeft

layout_alignParentRight

layout_alignParentTop

layout_alignParentBottom

layout_above

⎯ Example:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button 1"

android:layout_alignParentLeft="true"

android:layout_centerVertical="true" />

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button 2"

android:layout_toRightOf="@+id/button1"

android:layout_centerVertical="true" />

</RelativeLayout>

Table Layout

⎯ Attributes of Table Layout :

android:shrinkColumns="column_index"

android:stretchColumns="column_index"

android:collapseColumns="column_index"

android:gravity="alignment"

android:layout_span="column_count"

⎯ Example :

<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content">

<TableRow>

<TextView

android:text="Name"

android:layout_width="0dp"

android:layout_weight="1" />

<TextView

android:text="Age"

android:layout_width="0dp"

android:layout_weight="1" />

</TableRow>

<TableRow>

<TextView

android:text="John Doe"

android:layout_width="0dp"

android:layout_weight="1" />

<TextView

android:text="30"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_span="2" />

</TableRow>

</TableLayout>

Absolute Layout

⎯ Key Attributes:

o android:layout_x: Sets the horizontal position of the child view in pixels.

o android:layout_y: Sets the vertical position of the child view in pixels.


⎯ Example

<AbsoluteLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button 1"

android:layout_x="50px"

android:layout_y="100px" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello"

android:layout_x="150px"

android:layout_y="50px" />

</AbsoluteLayout>

Frame layout

⎯ Key Attributes:

o android:visibility :You can use the attribute on child views to control which one is

visible.

⎯ Example:

<FrameLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<ImageView

android:id="@+id/image1"
android:layout_width="match_parent"

android:layout_height="match_parent"

android:src="@drawable/image1"

android:visibility="visible" />

<ImageView

android:id="@+id/image2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:src="@drawable/image2"

android:visibility="invisible" />

</FrameLayout>
Unit 4:Designing User Interface with View

1.Write the attributes of OR Explain any four UI Components of Android application.

TextView :

⎯ A fundamental UI element that displays text on the screen.

⎯ Used to show labels, messages, and any other textual content within your

Android app.

⎯ Attributes of TextView :

android:text

android:textSize

android:gravity

android:layout_width

android:layout_height

android:hint

2. EditText :

⎯ A UI element that allows users to input text.

⎯ Attributes of EditText :

android:text

android:hint

android:maxLines

android:maxLength

3. Button :

⎯ A UI element that allows users to trigger an action.

⎯ Attributes of Button :

android:onClick

android:background

android:text

android:textSize

4. ImageButton :
⎯ A UI element that displays an image and behaves like a button.

⎯ When clicked, it triggers an action (like a regular Button).

android:id

android:layout_width

android:layout_height

android:src

android:onClick

5. ToggleButton :

⎯ ToggleButtons provide a simple way to represent on/off states or binary

choices within your Android application.

⎯ Key Attributes of ToggleButton :

android:id

android:layout_width

android:layout_height

android:textOn

android:textOff

6. RadioButton

⎯ RadioButtons allow users to select only one option from a group.

⎯ Key Attributes of RadioButton:

android:id

android:text

android:checked

android:button

8. ProgressBar :

⎯ ProgressBars provide visual feedback to the user about the progress of a task (e.g.,

downloading a file, loading data).

⎯ You can update the progress value programmatically in your code using

setProgress() method.
⎯ Key Attributes of ProgressBar :

android:id

android:layout_width

android:layout_height

android:max

android:progress

2. List different types of views? Explain Scroll view OR List View OR Grid View OR

Image View.

ListView

GridView

ScrollView

Imageview

ListView

⎯ XML File

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<ListView

android:id="@+id/listView"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

</ LinearLayout >

⎯ MainActivity.java
import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.*;

public class MainActivity extends AppCompatActivity

private ListView listView;

private List<String> items;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

listView = findViewById(R.id.listView);

items = new ArrayList<>();

items.add("Item 1");

items.add("Item 2");

items.add("Item 3");

ArrayAdapter<String> adapter = new ArrayAdapter<>

(this, android.R.layout.simple_list_item_1, items);

listView.setAdapter(adapter);

3. Explain the Toast with syntax.How to create custom toast.

Toast Alert in Android:

⎯ Toast in Android is a simple message that appears briefly on the screen to provide

feedback to the user.

Syntax :
Toast.makeText(this, "This is a Toast message", Toast.LENGTH_SHORT).show();

Custom_Toast.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@color/colorAccent"

android:padding="16dp">

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_check" />

<TextView

android:id="@+id/toast_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="16dp"

android:textColor="@android:color/white"

android:text="This is a custom Toast!" />

</LinearLayout>

Create the Toast in your Activity:

public class MainActivity extends AppCompatActivity

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Inflate the custom toast layout


LayoutInflater inflater = getLayoutInflater();

View toastLayout = inflater.inflate(R.layout.custom_toast, null);

// Get the TextView from the custom layout

TextView toastText = toastLayout.findViewById(R.id.toast_text);

toastText.setText("Your custom message here");

// Create and show the Toast

Toast toast = new Toast(getApplicationContext());

toast.setDuration(Toast.LENGTH_SHORT);

toast.setView(toastLayout);

toast.show();

4.Explain the use of Date & Time Picker with example

Time & Date Picker :

⎯ DatePicker and TimePicker are UI components in Android that allow users to

select dates and times respectively.

⎯ They provide a user-friendly interface for various applications like scheduling,

reminders, event planning, and more.

XML Code :

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center">

<Button
android:id="@+id/btnShowDatePicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Date Picker" />

<Button

android:id="@+id/btnShowTimePicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Time Picker" />

<TextView

android:id="@+id/tvSelectedDate"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:text="Selected Date:" />

<TextView

android:id="@+id/tvSelectedTime"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="16dp"

android:text="Selected Time:" />

</LinearLayout>

public class MainActivity extends AppCompatActivity

private TextView tvSelectedDate, tvSelectedTime;

private Button btnShowDatePicker, btnShowTimePicker;

private LinearLayout layout;

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tvSelectedDate = findViewById(R.id.tvSelectedDate);

tvSelectedTime = findViewById(R.id.tvSelectedTime);

btnShowDatePicker = findViewById(R.id.btnShowDatePicker);

btnShowTimePicker = findViewById(R.id.btnShowTimePicker);

layout = findViewById(R.id.layout);

btnShowDatePicker.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v)

showDatePicker();

});

btnShowTimePicker.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

showTimePicker();

});

private void showDatePicker() {

final Calendar calendar = Calendar.getInstance();

int year = calendar.get(Calendar.YEAR);

int month = calendar.get(Calendar.MONTH);

int day = calendar.get(Calendar.DAY_OF_MONTH);

DatePickerDialog datePickerDialog = new DatePickerDialog(this,

(view, year1, monthOfYear, dayOfMonth) -> {

Calendar selectedDate = Calendar.getInstance();


selectedDate.set(year1, monthOfYear, dayOfMonth);

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy",

Locale.getDefault());

String date = dateFormat.format(selectedDate.getTime());

tvSelectedDate.setText("Selected Date: " + date);

},

year, month, day);

datePickerDialog.show();

private void showTimePicker() {

final Calendar calendar = Calendar.getInstance();

int hour = calendar.get(Calendar.HOUR_OF_DAY);

int minute = calendar.get(Calendar.MINUTE);

TimePickerDialog timePickerDialog = new TimePickerDialog(this,

(view, hourOfDay, minuteOfDay) -> {

Calendar selectedTime = Calendar.getInstance();

selectedTime.set(Calendar.HOUR_OF_DAY, hourOfDay);

selectedTime.set(Calendar.MINUTE, minuteOfDay);

SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa",

Locale.getDefault());

String time = timeFormat.format(selectedTime.getTime());

tvSelectedTime.setText("Selected Time: " + time);

},

hour, minute,

android.text.format.DateFormat.is24HourFormat(this));

timePickerDialog.show();

You might also like