Chapter 4
Chapter 4
TextView
A user interface element that displays text to the user.
The following code sample shows a typical use, with an XML layout and code
to modify the contents of the text view:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_view_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/hello" />
</LinearLayout>
This code sample demonstrates how to modify the contents of the text view defined in the
previous XML layout:
<EditText
android:id="@+id/plain_text_input"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="text"/>
Choosing the input type configures the keyboard type that is shown,
acceptable characters, and appearance of the edit text.
EditText
EditText is a user interface control which is used to allow the user to enter or
modify the text.
AutoCompleteTextView
is an editable text view which is used to show the list of suggestions based on
the user typing text. The list of suggestions will be shown as a dropdown
menu from which the user can choose an item to replace the content of
textbox.
is a user interface control which is used to display a button with image and
to perform an action when user click or tap on it.
is a two states button that can be either checked or unchecked and it’s a
same as CheckBox control, except that it will allow only one option to select
from the group of options.
Radio Group is used to group one or more radio buttons into separate groups
based on our requirements.
setMessage()
setTitle()
setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) :
setProgressStyle(ProgressDialog.STYLE_SPINNER)
setMax()
getProgress() :
getMax()
show(Context context, CharSequence title, CharSequence message)\
incrementProgressBy(int diff)
ListView
2.Base Adapter:
BaseAdapter is a common base class of a general implementation of an Adapter that
can be used in ListView.
Whenever you need a customized list you create your own adapter and extend base
adapter in that.
Base Adapter can be extended to create a custom Adapter for displaying a custom
list item. ArrayAdapter is also an implementation of BaseAdapter.
GridView
GridView shows items in two-dimensional scrolling grid (rows & columns)
ImageView .
class is used to display an image file in application.
ImageView in android comes with different configuration options to support
different scale
scaleType options are used for scaling the bounds of an image to the bounds
of image view. Below are the listed scaleType configuration properties
supported.
CENTER: Places the image in center, but does not scale it.
CENTER_CROP: Scales the image uniformly.
CENTER_INSIDE: This will place the image inside the container and the edges of
the image will not overlap with that of the container, the image will be inside it.
FIT_CENTER: Scale the image from the center.
FIT_END: Scale the image from the end of the container, i.e from the right hand
side.
FIT_START: Scale the image from the start of the container, i.e from the left hand
side.
FIT_XY: This will fill the complete container with the image. This generally distorts
the image by stretching/sqeezing it in disproportionate ratios.
MATRIX: Used to scale the image using the image matrix when drawing.
ScrollView
ScrollView is a kind of layout which is useful to add a vertical or horizontal scroll
bars to the content which is larger than actual size of layouts such as
linearlayout, relativelayout, framelayout, etc.
ScrollView can hold only one direct child. In case, if we want to add multiple
views within the scroll view, then we need to include them in another standard
layout.
ScrollView supports only vertical scrolling. In case, if we want to
implement horizontal scrolling, then we need to
use HorizontalScrollView component.
The android ScrollView is having property called android:fillViewport, which is
used to define whether the ScrollView should stretch it’s content to fill the
viewport or not.
id and scrollbars are common attributes.
Toasts
A standard toast notification appears near the bottom of the screen, centered
horizontally. You can change this position with the setGravity(int, int, int) method. This
accepts three parameters: a Gravity constant, an x-position offset, and a y-position
offset.
For example:
toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
Creating Custom Toast View
Android provides controls for the user to pick a time or pick a date as ready-
to-use dialogs.
Each picker provides controls for selecting each part of the time (hour,
minute, AM/PM) or date (month, day, year).
Date Picker allows you to select the date consisting of day, month and year in
your custom user interface. For this functionality android provides DatePicker
and DatePickerDialog components.
DatePicker
DatePickerDialog
Time Picker
TimePickerDialog
A dialog that prompts the user for the time of day using a TimePicker.