0% found this document useful (0 votes)
31 views

3 Getting and Setting A View

This document discusses Android TextView and EditText widgets. It explains how to get and set values in TextViews, and the different methods for getting values from TextViews and EditTexts. It also covers type casting in Java and the differences between primitive and reference data types.
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)
31 views

3 Getting and Setting A View

This document discusses Android TextView and EditText widgets. It explains how to get and set values in TextViews, and the different methods for getting values from TextViews and EditTexts. It also covers type casting in Java and the differences between primitive and reference data types.
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/ 15

MARY ROSE C.

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):

ArrayList<int> myNumbers = new ArrayList<int>(); // Invalid


ArrayList<Integer> myNumbers = new ArrayList<Integer>(); //
Valid
 Android'sWebsite. (n.d.). Developers Guide. Retrieved from
https://androiddevelopers.googleblog.com/2020/06/11-
weeks-of-android-people-identity.html
 https://www.geeksforgeeks.org/primitive-data-type-vs-
object-data-type-in-java-with-examples/
 https://www.w3schools.com/java/java_wrapper_classes.asp
 https://chortle.ccsu.edu/java5/notes/chap09c/ch09C_2.htm
l

You might also like