3 Getting and Setting A View
3 Getting and Setting A View
COLUMBRES
At the end of this lesson, you should be able to:
Utilize the Android TextView, EditText;
Comprehend how to get and set values using TextView;
Apply the different methods in getting values using TextView
and EditText; and
Appreciate how TextView and EditText works.
A user interface element that displays text to the user. To
provide user-editable text.
The following code sample shows a typical use, with an XML
layout and codes to modify the contents of the text view:
Thiscode sample demonstrates how to modify the contents
of the text view defined in the previous XML layout:
A user interface element for entering and modifying text.
When you define an edittext widget, you must specify the
android.R.styleable#TextView_inputType attribute. For
example, for plain text input set inputType to "text“.
type casting means converting the type of a
primitive/reference variable.
three types of typecasting:
1. Primitive types
2. Object types
3. Wrapper Classes and primitives
The Java programming language is statically-typed, which
means that all variables must first be declared before they
can be used.
A primitive type is predefined by the language and is named
by a reserved keyword. Primitive values do not share a state
with other primitive values. The eight primitive data types
supported by the Java programming language are:
byte: The byte data type is an 8-bit signed two's complement
integer. It has a minimum value of -128 and a maximum value of
127 (inclusive). The byte data type can be useful for saving memory
in large arrays, where memory savings actually matters.
short: The short data type is a 16-bit signed two's complement
integer. It has a minimum value of -32,768 and a maximum value of
32,767 (inclusive).
int: By default, the int data type is a 32-bit signed two's
complement integer, which has a minimum value of -231 and a
maximum value of 231-1.
long: The long data type is a 64-bit two's complement integer. The
signed long has a minimum value of -263 and a maximum value of
263-1.
float: The float data type is a single-precision 32-bit IEEE 754 floating
point. Its range of values is beyond the scope of this discussion but is
specified in the Floating-Point Types, Formats, and Values section of the
Java Language Specification.
double: The double data type is a double-precision 64-bit IEEE 754
floating point. Its range of values is beyond the scope of this discussion
but is specified in the Floating-Point Types, Formats, and Values section
of the Java Language Specification.
boolean: The boolean data type has only two possible values: true and
false. Use this data type for simple flags that track true/false conditions.
This data type represents one bit of information, but its "size" isn't
something that's precisely defined.
char: The char data type is a single 16-bit Unicode character. It has a
minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or
65,535 inclusive).
An object is a large chunk of memory that can potentially
contain a great deal of data along with methods (little
programs) to process that data.
There are thousands of object classes that come standard
with Java, and a programmer can easily create additional
classes.
These are also referred to as Non-primitive or Reference Data
Type. They are so-called because they refer to any particular
object.
Difference
between the
primitive and
object data
types in a
tabular manner
as shown
below as
follows:
Wrapper classes provide a way to use primitive data types
(int, boolean, etc..) as objects.
The table below shows the primitive type and the equivalent
wrapper class:
Example
Sometimes you must use wrapper classes, for example when
working with Collection objects, such as ArrayList, where
primitive types cannot be used (the list can only store
objects):