Unit Ii
Unit Ii
Views are the user interacting elements in an Activity window. Actually a view draws something visible content on
the activity screen. All android Views are derived from an android class called View. Some of the popular android Views
(Widgets/controls/UI elements) are TextView, EditText, ImageView, Button etc.
View is the base class of all types of User Interface elements, Different Views such as ImageView, TextView, Button
ImageButton etc etc and different ViewGroups (Layouts) such as LinearLayout AbsoluteLayout, RelativeLayout,
TableLayout, ConstraintLayout etc etc are all derived from this View class since View is the top most class in the android
View System.
View class is derived from the Object class
The View class hierarchy is given below:
AutoComplet RadioGroup
eTextView
Where is the location of this View class? or where can we find the definition of this View class?
Go to the following package
android.view.
Different Views
1. TextView
2. ImageView
3. ViewGroup
4. Button
5. EditText
6. CompoundButton
7. RadioButton
8. CheckBox
9. Switch
10. ToggleButton
11. AdapterView
12. AbsSpinner
13. Spinner
14. AbsListView
15. ListView
16. LinearLayout
17. AbsoluteLayout
18. RelativeLayout
19. FrameLayout
20. ConstraintLayout
21. HorizontalScrollView
22. ScrollView
Note: All library classes has a naming convention in which all the staring letters of all words in the class name are
written in Capital letters.
Eg: HorizontalScrollView, AbsSpinner and Spinner etc.
While Camel notation is used in naming library methods in the library classes where, all letters of first word of the
method name is written in lower case letters, starting letters of all other words in the method name are written in Upper case
letters.
Eg: setContentView(),setOnCheckedChangeListener() etc.
How to make a view (or UI element, control, Widget)?
1. By Extending the System library class View and its various sub classes
<TextView>
<Button>
<EditText>
<LinearLayout></LinearLayout> etc
We choose the xml option to create various UI elements (Views, Controls, Widgets) in our android application because
it is little bit easier method rather than using pure Java View classes and its objects. Anyway, Android compiler will
convert all of our XML View tags in to corresponding GUI classes in Java at the time of compilation.
1. Using the TextView class and its methods (The location of TextView class is the package android.widget)
Example
<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Demo Text” />
</LinearLayout>
We choose the XML tag method, because it is more simple than the pure Java code.
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
}
}
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
3. EditText
EditText is another common Widget seen in most of the android apps, it allows the user to input a
multiline editable text.
There are two methods to create EditText View.
1. Using the EditText class and its methods (EditText is a direct Sub class of TextView class. The location of
EditText class is the package android.widget)
<EditText
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:hint=”User Name” />
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
B1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//Your code here
}
});
Just write the function which should be executed in connection with the Button (or any View) click event.
Just mention that function name in the onClick attribute of the <Button> (or any View) tag
Example:
public void DemoFn(View v)
{
//your code here which should be executed in connection with Click event
}
Link this function to a View (Button etc) using the standard attribute onClick
<Button
Android:onClick=”DemoFn” />
Example Method 1:
Layout File (XML File – activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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 View"
android:textColor="#FFFFFF" android:id="@+id/Btn1"/>
</LinearLayout>
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.view.View; import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;
B1.setOnClickListener(cl);
}
Method 2
Layout File (XML File – activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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 View"
android:textColor="#FFFFFF" android:id="@+id/Btn1"/>
</LinearLayout>
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;
}
}
);
}
}
Method 3
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.view.View; import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;
ts.show();
}
}
Static member variables (used to set the duration of the Toast message display) of Toast class
LENGTH_LONG
LENGTH_SHORT
Non static constructor of Toast class Toast(Context) – used to construct a Toast Object
A simple example for default Toast message Layout File (XML file – activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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 View"
android:textColor="#FFFFFF"
android:onClick="DemoFn"/>
</LinearLayout>
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void DemoFn(View v)
{
Toast t=Toast.makeText(this,"Simple default Toast
message",Toast.LENGTH_LONG);
t.show();
}
}
A simple example of Custom Toast Message
Layout File for the Toast Object (toast_layout.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Toast Message"
android:background="#0000FF"/>
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;
}
public void DemoFn(View v)
{
LayoutInflater li = getLayoutInflater();
View toastV = li.inflate(R.layout.toast_layout, null);
Toast t = new Toast(getApplicationContext());
t.setView(toastV);
t.setDuration(Toast.LENGTH_SHORT);
t.setGravity(Gravity.CENTER_HORIZONTAL & Gravity.CENTER_VERTICAL,0,0);
t.show();
}
}
4.ImageView
ImageView is used to display an image on the activity screen .
1. android:scaleType - Scale type options are used for scaling the bounds of an image to the bounds of the
imageview. Its possible values are center, centerCrop, fitXY, fitStart, fitEnd, centerInside, fitCenter and matrix
2. android:src – used to specify the source of the image (drawable) file
Note: Save your image file in the drawable folder of res folder. Use @drawable/imagereference in XML (Layout)
File to refer the image file, and use R.drawable.imagereference in Java (Activity) file to refer the image file.
ImageView example
Layout File (XML File – activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/androidlogo" />
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
5.ImageButton
ImageButton is similar to ImageView except it can be pushed like a Button.
In simple words we can say, ImageButton is a button with an image that can be pressed or clicked by the users.
Important Note: ImageButton has all the properties of a normal button so you can easily perform any event like click
or any other event which you can perform on a normal button.
Creation of An ImageButton
1. Using the ImageButton class (Derived from ImageView class) and its methods. Location of ImageView
class definition: android.widget package
2. Using XML tag < ImageButton> and its attributes
Attributes:
1. All Standard/Global attributes
2. All <Button> tag attributes
3. All <ImageView> tag attributes
ImageButton example
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
CheckBox in android is nothing but a two state button, checked and
unchecked states respectively. CheckBox is used to input more than one options
from a given set of options.
<CheckBox android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Red Color”
android:checked=”true”/>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;
if(v.getId()==R.id.CB1)
{
CheckBox c1 = (CheckBox) findViewById(R.id.CB1);
Toast t= Toast.makeText(this, c1.getText().toString(),
Toast.LENGTH_LONG);
t.show();
}
else if(v.getId()==R.id.CB2)
{
CheckBox c2 = (CheckBox) findViewById(R.id.CB2);
Toast t = Toast.makeText(this, c2.getText().toString(),
Toast.LENGTH_LONG);
t.show();
}
else if(v.getId()==R.id.CB3)
{
CheckBox c3 = (CheckBox) findViewById(R.id.CB3);
Toast t = Toast.makeText(this, c3.getText().toString(),
Toast.LENGTH_LONG);
t.show();
}
}
}
RadioButton
RadioButton is also a two state button just like the CheckBox, the two states are ‘checked’ and
‘unchecked’. It allows the user to input any one option from the given list of options. Example
Gender selection control found in forms, in which either ‘Male’ or ‘Female’ option can be selected
not both.
<RadioButton android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Male”
android:checked=”true”/>
An Example
<RadioGroup android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:orientation=”vertical”/>
<RadioButton android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Male”/>
<RadioButton android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Female”/>
</RadioButton>
A simple example of RadioButton and RadioGroup
Layout File (XML File – activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="@+id/RB1"
android:onClick="DemoFn" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="@+id/RB2"
android:onClick="DemoFn" />
</RadioGroup>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;
if(v.getId()==R.id.RB1)
{
RadioButton c1 = (RadioButton) findViewById(R.id.RB1);
Toast t= Toast.makeText(this,
c1.getText().toString(),Toast.LENGTH_LONG);
t.show();
}
else if(v.getId()==R.id.RB2)
{
RadioButton c2 = (RadioButton) findViewById(R.id.RB2);
Toast t = Toast.makeText(this,
c2.getText().toString(),Toast.LENGTH_LONG);
t.show();
}
}
}
Another Programme which displays the selected RadioButton text on clicking a Button View
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/RG1">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="@+id/RB1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="@+id/RB2"
/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Submit"
android:id="@+id/SBtn1"/>
</RadioGroup>
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
RadioGroup r= (RadioGroup)findViewById(R.id.RG1);
Button b= (Button)findViewById(R.id.SBtn1);
b.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
int i=r.getCheckedRadioButtonId();
RadioButton rb=(RadioButton)findViewById(i);
Toast t =
Toast.makeText(getApplicationContext(), rb.getText(),Toast.LENGTH_LONG);
t.show();
}
}
);
}
}
ToggleButton is also a two-state button the ON (Checked) and OFF (Unchecked)
state respectively. A toggle button allows the user to change a setting between two states.
1. Using ToggleButton class (a direct sub class of CompoundButton class). Its location:
android.widget package
2. Using <ToggleButton> xml tag and its attributes
Its attributes:
All standard (Global) attributes
All Button Attributes
android:checked – used to make the ToggleButton checked by default
android:textOn – used to specify a text when the ToggleButton is in ON state
androidTextOff - used to specify a text when the ToggleButton is in OFF state
A simple Programme
</LinearLayout>
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.ToggleButton;
tb.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast t =
Toast.makeText(getApplicationContext(), tb.getText(),Toast.LENGTH_LONG);
t.show();
}
}
);
}
}
ProgressBar
ProgressBar is an Android widget used to display the progress of a process. It shows a bar which
shows how are the operation has progressed. Some Progress bar shows a secondary progress bar
which shows the progress of the intermediate operation such the buffer level of stream playback
progress bar.
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
}
}
A Dynamic Determinate ProgressBar Example using Thread
Layout File (XML File – activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="100px"
android:id="@+id/PB1"/>
</LinearLayout>
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity implements Runnable
{
int progressvalue=0;
ProgressBar p;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
p=(ProgressBar)findViewById(R.id.PB1);
Thread t=new Thread(this,"ProgressBarThread");
t.start();
}
public void run()
{
int i=0;
while(i<100)
{
try
{
progressvalue++;
p.setProgress(progressvalue);
Thread.sleep(500);
}
catch (Exception e)
{
}
i++;
}
}
}
Spinner
Spinner is another important UI in android which is used to select a single item from the given list
of items, just like the Radio Button in a RadioGroup.
New concepts in connection with a Spinner , an AutoCompleteTextView and a ListView, that you
have to understand are
An AdapterView is a class which acts as a bridge between the data source (either a table from a
database or an Array) and the android UI element such as a Spinner and an
AutoCompleteTextView. It retrieves data items from the data source and organizes each item in
an appropriate layout such as simple_spinner_item. It also places each data items in a layout
used for the Spinner ListView such as simple_spinner_dropdown_view using the method
setDropDownViewResource(DropDownViewLayout). Use the setAdapter(Adapter) method to
attach an Adapter View object to any of the UI element such as Spinner and
AutoCompleteTextView.
Creation a Spinner
- Using Spinner class (Derived from AbsSpinner class). Its Location: android.widget package
- Using <Spinner> xml tag and its attributes (all standard attributes)
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.ToggleButton;
Spinner s= (Spinner)findViewById(R.id.SpinnerUI);
ArrayAdapter aa=new
ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,a);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(aa);
s.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener()
{
public void
onItemSelected(AdapterView<?> ab,View v, int index,long id)
{
Toast.makeText(getApplicationContext(),a[index],Toast.LENGTH_LONG).show();
}
public void
onNothingSelected(AdapterView<?> x)
{
}
}
);
}
}
AutoCompleteTextView
AutoCompleteTextView is an important android widget which is similar to EditText, except that it
shows a list of completion suggestions automatically while the user is typing. The list of
suggestions is displayed in a drop down menu. The user can choose an item from there to replace
the content of edit box with.
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
String z[]={"Red","Green","Blue","White","Golden"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView
actv=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> aa=new
ArrayAdapter<String>(this,android.R.layout.select_dialog_item,z);
actv.setThreshold(1);
actv.setAdapter(aa);
}
}
ListView
ListView is a type of AdapterView that displays a vertical list of scroll-able views and each
view is placed one below the other.
Using adapter, items are inserted into the list from an array or database. For displaying the
items in the list method setAdaptor() is used. setAdaptor() method conjoins an adapter with the
list.
Android ListView is a ViewGroup (Refer the View class hierarchy given above) that is used to
display the list of items in multiple rows and contains an adapter that automatically inserts the
items into the list.
Note : ListView is a ViewGroup to hold different Child Views
Creation of ListView
1. Using ListView class (A sub class derived from AbsListView class). Its Location:
android.widget package
2. Using XML tag <ListView> and its attributes
<ListView> tag attributes
All Standard attributes
android:divider – specifies a colour or a drawable image as the divider between two list
items in the ListView
android:dividerHeight – specifies the divider’s height
android:entries - Reference to an array resource that will populate the ListView
android:footerDividersEnabled - When set to false, the ListView will not draw the divider
before each footer view
android:headerDividersEnabled - When set to false, the ListView will not draw the divider
before each header view
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
String z[]={"Red","Green","Blue","White","Golden","Orange","Brown","Sky
Blue","Olive Green","Bright Red","Black","Majenta","Silver","Violet"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView ListOne=(ListView)findViewById(R.id.LV1);
ArrayAdapter<String> aa=new
ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,z);
ListOne.setAdapter(aa);
}
}
Grid View
Android GridView shows items in two-dimensional scrolling grid (rows & columns) and the
grid items are not necessarily predetermined but they automatically inserted to the layout using
a ListAdapter
An adapter actually bridges between UI components and the data source that fill data into
UI Component. Adapter can be used to supply the data to like Spinner, AutoCompleteTextView,
ListView, GridView etc.
The ListView and GridView are subclasses of AdapterView and they can be populated by
binding them to an Adapter, which retrieves data from an external source and creates a View that
represents each data entry.
A GridView looks like the image given below
Creation of GridView
1. Using the View class ‘GridView’ – derived from the ‘AbsListView’ class. Its location:
android.widget package
2. Using xml tag <GridView> and its attributes
<GridView> tag attributes
All Standard attributes such as android:layout_width, android:layout_height, id etc
android:verticalSpacing - Defines the default vertical spacing between rows. This could be in
px, dp, sp, in, or mm.
android:horizontalSpacing - Defines the default horizontal spacing between columns. This
could be in px, dp, sp, in, or mm.
android:columnWidth - This specifies the fixed width for each column. This could be in px,
dp, sp, in, or mm.
android:numColumns - Defines how many columns to show. May be an integer value, such
as "100" or auto_fit which means display as many columns as possible to fill the available
space.
android:stretchMode - Defines how columns should stretch to fill the available empty space, if any.
This must be either of the values −
• none − Stretching is disabled.
• spacingWidth − The spacing between each column is stretched.
• columnWidth − Each column is stretched equally.
• spacingWidthUniform − The spacing between each column is uniformly stretched.
Note : Just like ListView, GridView is also a ViewGroup to hold different Child Views, both are
derived from AbsListView class. Please refer View class hierarchy which is given above.
Note: We can use simply a <GridView> in our layout without nesting it in any other ViewGroup
Object such as LinearLayout since GridView itself is a ViewGroup like LinearLayout. But in our
example, we have nested our GridView in a LinearLayout. But it is not mandatory.
A Simple GridView Example
Layout File (XML File – activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="@+id/GV1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="4"
android:horizontalSpacing="4px"
android:verticalSpacing="50px"/>
</LinearLayout>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
String z[]={"Red","Green","Blue","White","Golden","Orange","Brown","Sky
Blue","Olive Green","Bright
Red","Black","Majenta","Silver","Violet","Red","Green","Blue","White","Gold
en","Orange","Brown","Sky Blue","Olive Green","Bright
Red","Black","Majenta","Silver","Violet","Red","Green","Blue","White","Gold
en","Orange","Brown","Sky Blue","Olive Green","Bright
Red","Black","Majenta","Silver","Violet","Red","Green","Blue","White","Gold
en","Orange","Brown","Sky Blue","Olive Green","Bright
Red","Black","Majenta","Silver","Violet"};
GridView GridOne=(GridView)findViewById(R.id.GV1);
ArrayAdapter<String> aa=new
ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,z);
GridOne.setAdapter(aa);
}
}
ScrollView
ScrollView is another important View in android. The android.widget.ScrollView class provides the
functionality of scroll view. ScrollView is used to scroll the child elements of palette inside ScrollView.
Android supports vertical scroll view as default scroll view. Vertical ScrollView scrolls elements
vertically. Android uses HorizontalScrollView class for horizontal ScrollView.
As we all know ListView and GridView are also vertically scrollable, but they receive the data from an
external source (Data base or and Array), but our ScrollView does not insist on a Data base as well as
an Array instead it places all types of Views in a vertically scrollable View.
Note: ScrollView is better to view an UI element which has content larger than the height of the
window. Use a LinearLayout element within the ScrollView element
1. Using the view class ScrollView (a Sub class of FrameLayout class, please refer the View Class
hierarchy which is given at the beginning of the note). Its location: android.widget package
2. Using XML tag <ScrollView></scrollView> and its attributes
</ScrollView>
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
}
TimePicker
Android Time Picker allows you to select the time of day in either 24 hour or AM/PM
mode. The time consists of hours, minutes and clock format. Android provides this functionality
through TimePicker class.
</LinearLayout>
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
DatePicker
Android Date Picker allows you to select the date consisting of day, month and year in your
custom user interface. Android provides this functionality through DatePicker class.
package com.example.myapp1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;