Nis Assignment
Nis Assignment
Java JDK
⎯ The Java Development Kit (JDK) is a software development environment used for
Android SDK
⎯ Android development starts with the Android SDK (Software Development Kit).
• Debugger
• Libraries
• Emulator
• 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
⎯ 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
Android phone, tablet, Wear OS, Android TV, or Automotive OS device that you want to
2. Click Create Virtual Device, at the bottom of the AVD Manager dialog.
If you don't see the hardware profile you want, you can create or import a hardware profile.
⎯ As we know the modern JVM is high performance and provides excellent memory
⎯ 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.
⎯ View
• Examples:
⎯ ViewGroup
• Container that holds and organizes other Views (or even other ViewGroups).
• Examples:
⎯ Fragment
• Benefits:
o Adaptability: Easily adapt UI for different screen sizes (phones vs. tablets).
⎯ Activity
• Responsible for:
Linear Layout
⎯ Key Attributes:
o android:orientation:
⎯ 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"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</LinearLayout>
Relative Layout
⎯ Key Attributes:
layout_alignParentLeft
layout_alignParentRight
layout_alignParentTop
layout_alignParentBottom
layout_above
⎯ Example:
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
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:
<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
TextView :
⎯ 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 :
⎯ Attributes of EditText :
android:text
android:hint
android:maxLines
android:maxLength
3. Button :
⎯ 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.
android:id
android:layout_width
android:layout_height
android:src
android:onClick
5. ToggleButton :
android:id
android:layout_width
android:layout_height
android:textOn
android:textOff
6. 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.,
⎯ 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
<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" />
⎯ MainActivity.java
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.*;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.listView);
items.add("Item 1");
items.add("Item 2");
items.add("Item 3");
listView.setAdapter(adapter);
⎯ Toast in Android is a simple message that appears briefly on the screen to provide
Syntax :
Toast.makeText(this, "This is a Toast message", Toast.LENGTH_SHORT).show();
Custom_Toast.xml
<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"
</LinearLayout>
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(toastLayout);
toast.show();
XML Code :
<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"
<Button
android:id="@+id/btnShowTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<TextView
android:id="@+id/tvSelectedDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
<TextView
android:id="@+id/tvSelectedTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
</LinearLayout>
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
showDatePicker();
});
btnShowTimePicker.setOnClickListener(new View.OnClickListener()
@Override
showTimePicker();
});
Locale.getDefault());
},
datePickerDialog.show();
selectedTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
selectedTime.set(Calendar.MINUTE, minuteOfDay);
Locale.getDefault());
},
hour, minute,
android.text.format.DateFormat.is24HourFormat(this));
timePickerDialog.show();