SlideShare a Scribd company logo
1
Android Programming
T.ABIRAMI/KEC
Dr.T.Abirami
Associate Professor
Department of IT
Kongu Engineering College
abiananthmca@gmail.com
XML in Android
 XML stands for Extensible Markup Language.
 XML is a markup language much like HTML
used to describe data
 XML tags are not predefined
T.ABIRAMI/KEC 2
XML Syntax
//This line is called the XML prolog:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
T.ABIRAMI/KEC 3
XML Elements
 An XML element is everything from
(including) the element's start tag to
(including) the element's end tag.
An element can contain:
 text
 attributes
 other elements
 or a mix of the above
T.ABIRAMI/KEC 4
XML Naming Rules
XML elements must follow these naming rules:
 Element names are case-sensitive
 Element names must start with a letter or
underscore
 Element names cannot start with the letters xml
(or XML, or Xml, etc)
 Element names can contain letters, digits,
hyphens, underscores, and periods
 Element names cannot contain spaces
 Any name can be used, no words are reserved
T.ABIRAMI/KEC 5
 xmlns:android Defines the Android namespace.
 Namespaces are how you access all the Android
attributes and tags that are defined by Google
 This attribute should always be set to
"http://schemas.android.com/apk/res/android".
 In your example, the Namespace Prefix is
"android" and the Namespace URI is
"http://schemas.android.com/apk/res/android"
T.ABIRAMI/KEC 6
xmlns:android
xmlns:android
 The xmlns attribute declares an XML
Namespace.

 Namespaces are used to avoid conflicts between
element names when mixing XML languages.
 Name Space in order to specify that the
attributes listed below, belongs to Android.
Thus they starts with "android:"
T.ABIRAMI/KEC 7
 <Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=“Submit" />
T.ABIRAMI/KEC 8
Syntax
 <RootTag
xmlns:android="http://schemas.android.c
om/apk/res/android"
xmlns:tools="http://schemas.android
.com/tools" >
T.ABIRAMI/KEC 9
XML Example
<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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
Understanding the default activity Code
 MainActivity: It is the name of the class we are having. It is also
named as your activity name. If you remember the project creation we
have given this name.
 ActionBarActivity : Our class MainActivity is extending this class.
 onCreate(Bundle savedInstanceState): This is an overridden
method. It is inside the ActionBarActivity class.
 This method will be executed when the app is opened (the activity is
created). So basically you can think that it is the main method.
 Bundle: It is another predefined class. It is basically used for passing
data between android activities.
 setContentView(R.layout.activity_main): This method takes a
layout and it set the view as the layout to the activity.
 We created a layout named activity_main.xml. As I told you before
that all the ids for all the components are generated automatically and
stored inside R.java file. We are selecting the id of our layout from
R.java file (R.layout.activity_main).
T.ABIRAMI/KEC 11
View class
 It is a superclass for all GUI components
in Android.
Commonly used Views are :
 EditText
 ImageView
 TextView
 Button
 ImageButton
 CheckBox etc…
T.ABIRAMI/KEC 12
Initializing a View
 predefined class named View in android.
 For initializing a View from XML layout file,
we have a method findViewById().
T.ABIRAMI/KEC 13
findViewById(int id)
 R is a Class in android that are having the
id’s of all the view’s.
 findViewById() is a call to a function by a
reference of View class
 findViewById is a method that finds the
view from the layout resource file that are
attached with current Activity.
 to find xml id
T.ABIRAMI/KEC 14
Syntax
Declaration of UI
UIclassname objectname=(Uiclassname) findViewById(R.id.UniqueUI
_ID);
Button button = (Button) findViewById(R.id.button_send);
Button
 It represents a push button.
 A Push buttons can be clicked, or pressed by the user to
perform an action.
 There are different types of buttons used in android such as
CompoundButton, ToggleButton, RadioButton ,
ImageButton etc..
 Android buttons are GUI components which are sensible to
taps (clicks) by the user.
 It perform different actions or events like click event,
pressed event, touch event etc.
T.ABIRAMI/KEC 16
Button
 View is the superclass for all widgets and
the OnClickListener interface belongs to
this class
Button
 Create the button object
 Use OnClickListner to make it listen to the
user's click
 Use onClick to execute actions after the
user clicks the button
T.ABIRAMI/KEC 17
Handling Click events in Button | Android
There are 2 ways to handle the click event
in button
1. Onclick in xml layout
2. Using an OnClickListener interface
T.ABIRAMI/KEC 18
Onclick in XML layout
 When the user clicks a button, the Button
object receives an on-click event.
 To make click event work
add android:onClick attribute to the
Button element in your XML layout.
 The value for this attribute must be the
name of the method you want to call in
response to a click event.
T.ABIRAMI/KEC 19
Onclick in xml layout
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
/>
T.ABIRAMI/KEC 20
In MainActivity class : Onclick in
xml layout
 /** Called when the user touches the
button */
 public void sendMessage(View view)
 {
 // Do something in response to
button click
 }
T.ABIRAMI/KEC 21
Make sure that your sendMessage method should have the following :
•Be public
•Return void
•Define a View as its only parameter (this will be the View that was
clicked)
Using an OnClickListener : Operation on button
button.setOnClickListener ( new View.OnClickListener()
{
public void onClick(View v)
{
// Do something in response to button click
}
}
);
T.ABIRAMI/KEC 22
 public class MainActivity extends ActionBarActivity
 {Button b;
 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
 super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button1);
 b.setOnClickListener(new View.OnClickListener() { @Override
 public void onClick(View arg0) {
 // TODO Auto-generated method stub
 }
 });
 }
 }
T.ABIRAMI/KEC 23
Handling EditText
 getText(): This method returns an
Editable instance. And it contains the text
from the EditText.
 So for storing the Text into a String
object,
 use the toString() method to convert it
into String.
 setText(String s):This method takes a
string and set the string to EditText.
T.ABIRAMI/KEC 24
Input From user
1. using setText()
tt.setText(Integer.toString(z));
2.using getText()
x=Integer.parseInt(amount1.getText().toString());
 private void showMessage(){
 String s = editText.getText().toString();
 String greeting = "Hello "+s;
 editText.setText(greeting);
 }
T.ABIRAMI/KEC 26
Android Toast class
 Toast can be used to display information for the short
period of time.
 Toast class is used to show notification for a particular
interval of time. After sometime it disappears.
 It doesn't block the user interaction.
 A toast contains message to be displayed quickly and
disappears after sometime.
 android.widget.Toast class is the subclass of
java.lang.Object class.
T.ABIRAMI/KEC 27
Constants of Toast class
Constant Description
public static final int
LENGTH_LONG
displays view for the long
duration of time.
public static final int
LENGTH_SHORT
displays view for the short
duration of time.
T.ABIRAMI/KEC 28
Methods of Toast class
Method Description
public static Toast makeText(Context
context, CharSequence text, int
duration)
makes the toast
containing text and
duration.
public void show() displays toast.
public void setMargin (float
horizontalMargin, float verticalMargin)
changes the horizontal
and vertical margin
difference.
T.ABIRAMI/KEC 29
Example
Toast.makeText(getApplicationC
ontext(),"Hello Javatpoint",Toast
.LENGTH_SHORT).show();
T.ABIRAMI/KEC 30
 Toast toast=Toast.makeText(getApplicatio
nContext(),"Hello Javatpoint",Toast.LENGT
H_SHORT);
 toast.setMargin(50,50);
 toast.show();
T.ABIRAMI/KEC 31
DDMS (Dalvik Debug Monitor
Server)
 It is integrated into Eclipse and is also
shipped in the tools/ directory of the SDK.
 It works with both the emulator and a
connected device. If both are connected and
running simultaneously, DDMS defaults to
the emulator.
 The service could include message
formation, call spoofing, capturing
screenshot, exploring internal threads and
file systems etc..
T.ABIRAMI/KEC 32
TextView UI control / Class
 To display text on the screen
Class Heirarchy:
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
T.ABIRAMI/KEC 33
Xml code
 <TextView
android:id="@+id/text_view_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text=“Test" />
T.ABIRAMI/KEC 34
Attributes
 android:typeface="sans"
android:textColor="@color/colorPrimary“
 textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,15);
 textView.setTextColor(Color.RED);
T.ABIRAMI/KEC 35
T.ABIRAMI/KEC 36
ATTRIBUTES DESCRIPTION
android:text Sets text of the Textview
android:id Gives a unique ID to the Textview
android:cursorVisible Use this attribute to make cursor visible or invisible. Default value is visible.
android:drawableBottom Sets images or other graphic assets to below of the Textview.
android:drawableEnd Sets images or other graphic assets to end of Textview.
android:drawableLeft Sets images or other graphic assets to left of Textview.
android:drawablePadding Sets padding to the drawable(images or other graphic assets) in the Textview.
android:autoLink This attribute is used to automatically detect url or emails and show it as clickable link.
android:autoText Automatically correct spelling errors in text of the Textview.
android:capitalize It automatically capitalize whatever the user types in the Textview.
android:drawableRight Sets drawables to right of text in the Textview.
android:drawableStart Sets drawables to start of text in the Textview.
android:drawableTop Sets drawables to top of text in the Textview.
android:ellipsize Use this attribute when you want text to be ellipsized if it is longer than the Textview width.
android:ems Sets width of the Textview in ems.
android:gravity We can align text of the Textview vertically or horizontally or both.
android:height Use to set height of the Textview.
android:hint Use to show hint when there is no text.
android:inputType Use to set input type of the Textview. It can be Number, Password, Phone etc.
android:lines Use to set height of the Textview by number of lines.
android:maxHeight Sets maximum height of the Textview.
android:minHeight Sets minimum height of the Textview.
android:maxLength Sets maximum character length of the Textview.
android:maxLines Sets maximum lines Textview can have.
android:minLines Sets minimum lines Textview can have.
android:maxWidth Sets maximum width Textview can have.
android:minWidth Sets minimum lines Textview can have.
android:textAllCaps Show all texts of the Textview in capital letters.
android:textColor Sets color of the text.
android:textSize Sets font size of the text.
android:textStyle Sets style of the text. For example, bold, italic, bolditalic.
android:typeface Sets typeface or font of the text. For example, normal, sans, serif etc
android:width Sets width of the TextView.
Java Code
 TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Android"); //set text for text view
 textView.setTextSize(20);
 textView.setBackgroundColor(Color.BLACK);//set background
color
T.ABIRAMI/KEC 37
EditText
 It is a user interface control
 It is used to allow the user to enter or
modify the text.
Package Stru..
java.lang.Object
↳android.view.View
↳android.widget.TextView
↳android.widget.EditText
T.ABIRAMI/KEC 38
EditText :Attributes Inherited from TextView Class
<EditText
android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject"
android:inputType="text"/>
T.ABIRAMI/KEC 39
EditText Attributes
Attribute Description
android:id It is used to uniquely identify the control
android:gravity It is used to specify how to align the text like left, right, center, top,
etc.
android:text It is used to set the text.
android:hint It is used to display the hint text when text is empty
android:textColor It is used to change the color of the text.
android:textColorHint It is used to change the text color of hint text.
android:textSize It is used to specify the size of the text.
android:textStyle It is used to change the style (bold, italic, bolditalic) of text.
android:background It is used to set the background color for edit text control
android:ems It is used to make the textview be exactly this many ems wide.
android:width It makes the TextView be exactly this many pixels wide.
android:height It makes the TextView be exactly this many pixels tall.
android:maxWidth It is used to make the TextView be at most this many pixels wide.
android:minWidth It is used to make the TextView be at least this many pixels wide.
android:textAllCaps It is used to present the text in all CAPS
android:typeface It is used to specify the Typeface (normal, sans, serif, monospace)
for the text.
android:textColorHighlight It is used to change the color of text selection highlight.
android:inputType It is used to specify the type of text being placed in text fields.
android:fontFamily It is used to specify the fontFamily for the text.
android:editable If we set false, EditText won't allow us to enter or modify the text
T.ABIRAMI/KEC 40
 public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText et = (EditText) findViewById(R.id.txtSub);
String name = et.getText().toString();
}
}
T.ABIRAMI/KEC 41
EditText simpleEditText = (EditText) findViewById(R.id.et_simple);
String strValue = simpleEditText.getText().toString();
Validating your Text
if (name.getText().toString().isEmpty()|| password.getText().toString().isEmpty()
|| email.getText().toString().isEmpty() || dob.getText().toString().isEmpty()
|| phoneno.getText().toString().isEmpty())
{
result.setText("Please Fill All the Details")
}
else
{
result.setText(name.getText().toString() + password.getText().toString()
+ email.getText().toString() + dob.getText().toString()
+ phoneno.getText().toString())
}
T.ABIRAMI/KEC 42
EditText Example
T.ABIRAMI/KEC 43

More Related Content

PPT
Android Bootcamp Tanzania:understanding ui in_android
Denis Minja
 
PPT
Basic of Abstract Window Toolkit(AWT) in Java
suraj pandey
 
PDF
Lab1-android
Lilia Sfaxi
 
PPTX
GUI components in Java
kirupasuchi1996
 
PDF
Action Bar in Android
Prof. Erwin Globio
 
PDF
Android Application Development - Level 2
Isham Rashik
 
PDF
Quick Intro to Android Development
Jussi Pohjolainen
 
DOCX
Android basics – dialogs and floating activities
info_zybotech
 
Android Bootcamp Tanzania:understanding ui in_android
Denis Minja
 
Basic of Abstract Window Toolkit(AWT) in Java
suraj pandey
 
Lab1-android
Lilia Sfaxi
 
GUI components in Java
kirupasuchi1996
 
Action Bar in Android
Prof. Erwin Globio
 
Android Application Development - Level 2
Isham Rashik
 
Quick Intro to Android Development
Jussi Pohjolainen
 
Android basics – dialogs and floating activities
info_zybotech
 

Similar to Android Application Development Programming (20)

PPTX
iOS Development (Part 2)
Asim Rais Siddiqui
 
PPTX
Handling action bar in Android
indiangarg
 
DOC
Csharp
vinayabburi
 
PPT
Android User Interface: Basic Form Widgets
Ahsanul Karim
 
PPTX
Android apps development
Monir Zzaman
 
PPT
Unit 5.133333333333333333333333333333333.ppt
geetav5
 
DOCX
UIAutomator
Sandip Ganguli
 
PDF
Android development - Activities, Views & Intents
Lope Emano
 
PPT
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindiappsdevelopment
 
PPT
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
PPTX
JAVA AWT
shanmuga rajan
 
PPTX
02 hello world - Android
Wingston
 
DOCX
Activity
roopa_slide
 
DOCX
Activity
NikithaNag
 
DOCX
Activity
NikithaNag
 
DOCX
Activity
roopa_slide
 
PPTX
08ui.pptx
KabadaSori
 
PPTX
Android 3
Robert Cooper
 
PPTX
Android
Pranav Ashok
 
PPTX
Introduction to JavaScript DOM and User Input.pptx
GevitaChinnaiah
 
iOS Development (Part 2)
Asim Rais Siddiqui
 
Handling action bar in Android
indiangarg
 
Csharp
vinayabburi
 
Android User Interface: Basic Form Widgets
Ahsanul Karim
 
Android apps development
Monir Zzaman
 
Unit 5.133333333333333333333333333333333.ppt
geetav5
 
UIAutomator
Sandip Ganguli
 
Android development - Activities, Views & Intents
Lope Emano
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindiappsdevelopment
 
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
JAVA AWT
shanmuga rajan
 
02 hello world - Android
Wingston
 
Activity
roopa_slide
 
Activity
NikithaNag
 
Activity
NikithaNag
 
Activity
roopa_slide
 
08ui.pptx
KabadaSori
 
Android 3
Robert Cooper
 
Android
Pranav Ashok
 
Introduction to JavaScript DOM and User Input.pptx
GevitaChinnaiah
 
Ad

More from Kongu Engineering College, Perundurai, Erode (20)

PPTX
Event Handling -_GET _ POSTimplementation.pptx
Kongu Engineering College, Perundurai, Erode
 
PPTX
Introduction to Generative AI refers to a subset of artificial intelligence
Kongu Engineering College, Perundurai, Erode
 
PPTX
Introduction to Microsoft Power BI is a business analytics service
Kongu Engineering College, Perundurai, Erode
 
PPTX
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQ...
Kongu Engineering College, Perundurai, Erode
 
PPTX
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
PPTX
Node.js web-based Example :Run a local server in order to start using node.js...
Kongu Engineering College, Perundurai, Erode
 
PPT
Concepts of Satellite Communication and types and its applications
Kongu Engineering College, Perundurai, Erode
 
PPT
Concepts of Mobile Communication Wireless LANs, Bluetooth , HiperLAN
Kongu Engineering College, Perundurai, Erode
 
PPTX
Web Technology Introduction framework.pptx
Kongu Engineering College, Perundurai, Erode
 
PPTX
Computer Network - Unicast Routing Distance vector Link state vector
Kongu Engineering College, Perundurai, Erode
 
PPT
Android SQLite database oriented application development
Kongu Engineering College, Perundurai, Erode
 
PPTX
Introduction to Spring & Spring BootFramework
Kongu Engineering College, Perundurai, Erode
 
PPTX
A REST API (also called a RESTful API or RESTful web API) is an application p...
Kongu Engineering College, Perundurai, Erode
 
PPTX
SOA and Monolith Architecture - Micro Services.pptx
Kongu Engineering College, Perundurai, Erode
 
PPTX
Connect to NoSQL Database using Node JS.pptx
Kongu Engineering College, Perundurai, Erode
 
PPTX
Bootstarp installation.pptx
Kongu Engineering College, Perundurai, Erode
 
PPTX
nested_Object as Parameter & Recursion_Later_commamd.pptx
Kongu Engineering College, Perundurai, Erode
 
Event Handling -_GET _ POSTimplementation.pptx
Kongu Engineering College, Perundurai, Erode
 
Introduction to Generative AI refers to a subset of artificial intelligence
Kongu Engineering College, Perundurai, Erode
 
Introduction to Microsoft Power BI is a business analytics service
Kongu Engineering College, Perundurai, Erode
 
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQ...
Kongu Engineering College, Perundurai, Erode
 
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
Node.js web-based Example :Run a local server in order to start using node.js...
Kongu Engineering College, Perundurai, Erode
 
Concepts of Satellite Communication and types and its applications
Kongu Engineering College, Perundurai, Erode
 
Concepts of Mobile Communication Wireless LANs, Bluetooth , HiperLAN
Kongu Engineering College, Perundurai, Erode
 
Web Technology Introduction framework.pptx
Kongu Engineering College, Perundurai, Erode
 
Computer Network - Unicast Routing Distance vector Link state vector
Kongu Engineering College, Perundurai, Erode
 
Android SQLite database oriented application development
Kongu Engineering College, Perundurai, Erode
 
Introduction to Spring & Spring BootFramework
Kongu Engineering College, Perundurai, Erode
 
A REST API (also called a RESTful API or RESTful web API) is an application p...
Kongu Engineering College, Perundurai, Erode
 
SOA and Monolith Architecture - Micro Services.pptx
Kongu Engineering College, Perundurai, Erode
 
Connect to NoSQL Database using Node JS.pptx
Kongu Engineering College, Perundurai, Erode
 
nested_Object as Parameter & Recursion_Later_commamd.pptx
Kongu Engineering College, Perundurai, Erode
 
Ad

Recently uploaded (20)

PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PPTX
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PDF
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
Information Retrieval and Extraction - Module 7
premSankar19
 
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
Introduction to Data Science: data science process
ShivarkarSandip
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 

Android Application Development Programming

  • 2. XML in Android  XML stands for Extensible Markup Language.  XML is a markup language much like HTML used to describe data  XML tags are not predefined T.ABIRAMI/KEC 2
  • 3. XML Syntax //This line is called the XML prolog: <?xml version="1.0" encoding="UTF-8"?> <root> <child> <subchild>.....</subchild> </child> </root> T.ABIRAMI/KEC 3
  • 4. XML Elements  An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can contain:  text  attributes  other elements  or a mix of the above T.ABIRAMI/KEC 4
  • 5. XML Naming Rules XML elements must follow these naming rules:  Element names are case-sensitive  Element names must start with a letter or underscore  Element names cannot start with the letters xml (or XML, or Xml, etc)  Element names can contain letters, digits, hyphens, underscores, and periods  Element names cannot contain spaces  Any name can be used, no words are reserved T.ABIRAMI/KEC 5
  • 6.  xmlns:android Defines the Android namespace.  Namespaces are how you access all the Android attributes and tags that are defined by Google  This attribute should always be set to "http://schemas.android.com/apk/res/android".  In your example, the Namespace Prefix is "android" and the Namespace URI is "http://schemas.android.com/apk/res/android" T.ABIRAMI/KEC 6 xmlns:android
  • 7. xmlns:android  The xmlns attribute declares an XML Namespace.   Namespaces are used to avoid conflicts between element names when mixing XML languages.  Name Space in order to specify that the attributes listed below, belongs to Android. Thus they starts with "android:" T.ABIRAMI/KEC 7
  • 11. Understanding the default activity Code  MainActivity: It is the name of the class we are having. It is also named as your activity name. If you remember the project creation we have given this name.  ActionBarActivity : Our class MainActivity is extending this class.  onCreate(Bundle savedInstanceState): This is an overridden method. It is inside the ActionBarActivity class.  This method will be executed when the app is opened (the activity is created). So basically you can think that it is the main method.  Bundle: It is another predefined class. It is basically used for passing data between android activities.  setContentView(R.layout.activity_main): This method takes a layout and it set the view as the layout to the activity.  We created a layout named activity_main.xml. As I told you before that all the ids for all the components are generated automatically and stored inside R.java file. We are selecting the id of our layout from R.java file (R.layout.activity_main). T.ABIRAMI/KEC 11
  • 12. View class  It is a superclass for all GUI components in Android. Commonly used Views are :  EditText  ImageView  TextView  Button  ImageButton  CheckBox etc… T.ABIRAMI/KEC 12
  • 13. Initializing a View  predefined class named View in android.  For initializing a View from XML layout file, we have a method findViewById(). T.ABIRAMI/KEC 13
  • 14. findViewById(int id)  R is a Class in android that are having the id’s of all the view’s.  findViewById() is a call to a function by a reference of View class  findViewById is a method that finds the view from the layout resource file that are attached with current Activity.  to find xml id T.ABIRAMI/KEC 14
  • 15. Syntax Declaration of UI UIclassname objectname=(Uiclassname) findViewById(R.id.UniqueUI _ID); Button button = (Button) findViewById(R.id.button_send);
  • 16. Button  It represents a push button.  A Push buttons can be clicked, or pressed by the user to perform an action.  There are different types of buttons used in android such as CompoundButton, ToggleButton, RadioButton , ImageButton etc..  Android buttons are GUI components which are sensible to taps (clicks) by the user.  It perform different actions or events like click event, pressed event, touch event etc. T.ABIRAMI/KEC 16
  • 17. Button  View is the superclass for all widgets and the OnClickListener interface belongs to this class Button  Create the button object  Use OnClickListner to make it listen to the user's click  Use onClick to execute actions after the user clicks the button T.ABIRAMI/KEC 17
  • 18. Handling Click events in Button | Android There are 2 ways to handle the click event in button 1. Onclick in xml layout 2. Using an OnClickListener interface T.ABIRAMI/KEC 18
  • 19. Onclick in XML layout  When the user clicks a button, the Button object receives an on-click event.  To make click event work add android:onClick attribute to the Button element in your XML layout.  The value for this attribute must be the name of the method you want to call in response to a click event. T.ABIRAMI/KEC 19
  • 20. Onclick in xml layout <Button android:id="@+id/button_send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" android:onClick="sendMessage" /> T.ABIRAMI/KEC 20
  • 21. In MainActivity class : Onclick in xml layout  /** Called when the user touches the button */  public void sendMessage(View view)  {  // Do something in response to button click  } T.ABIRAMI/KEC 21 Make sure that your sendMessage method should have the following : •Be public •Return void •Define a View as its only parameter (this will be the View that was clicked)
  • 22. Using an OnClickListener : Operation on button button.setOnClickListener ( new View.OnClickListener() { public void onClick(View v) { // Do something in response to button click } } ); T.ABIRAMI/KEC 22
  • 23.  public class MainActivity extends ActionBarActivity  {Button b;  @Override  protected void onCreate(Bundle savedInstanceState)  {  super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b=(Button)findViewById(R.id.button1);  b.setOnClickListener(new View.OnClickListener() { @Override  public void onClick(View arg0) {  // TODO Auto-generated method stub  }  });  }  } T.ABIRAMI/KEC 23
  • 24. Handling EditText  getText(): This method returns an Editable instance. And it contains the text from the EditText.  So for storing the Text into a String object,  use the toString() method to convert it into String.  setText(String s):This method takes a string and set the string to EditText. T.ABIRAMI/KEC 24
  • 25. Input From user 1. using setText() tt.setText(Integer.toString(z)); 2.using getText() x=Integer.parseInt(amount1.getText().toString());
  • 26.  private void showMessage(){  String s = editText.getText().toString();  String greeting = "Hello "+s;  editText.setText(greeting);  } T.ABIRAMI/KEC 26
  • 27. Android Toast class  Toast can be used to display information for the short period of time.  Toast class is used to show notification for a particular interval of time. After sometime it disappears.  It doesn't block the user interaction.  A toast contains message to be displayed quickly and disappears after sometime.  android.widget.Toast class is the subclass of java.lang.Object class. T.ABIRAMI/KEC 27
  • 28. Constants of Toast class Constant Description public static final int LENGTH_LONG displays view for the long duration of time. public static final int LENGTH_SHORT displays view for the short duration of time. T.ABIRAMI/KEC 28
  • 29. Methods of Toast class Method Description public static Toast makeText(Context context, CharSequence text, int duration) makes the toast containing text and duration. public void show() displays toast. public void setMargin (float horizontalMargin, float verticalMargin) changes the horizontal and vertical margin difference. T.ABIRAMI/KEC 29
  • 31.  Toast toast=Toast.makeText(getApplicatio nContext(),"Hello Javatpoint",Toast.LENGT H_SHORT);  toast.setMargin(50,50);  toast.show(); T.ABIRAMI/KEC 31
  • 32. DDMS (Dalvik Debug Monitor Server)  It is integrated into Eclipse and is also shipped in the tools/ directory of the SDK.  It works with both the emulator and a connected device. If both are connected and running simultaneously, DDMS defaults to the emulator.  The service could include message formation, call spoofing, capturing screenshot, exploring internal threads and file systems etc.. T.ABIRAMI/KEC 32
  • 33. TextView UI control / Class  To display text on the screen Class Heirarchy: java.lang.Object ↳ android.view.View ↳ android.widget.TextView T.ABIRAMI/KEC 33
  • 36. T.ABIRAMI/KEC 36 ATTRIBUTES DESCRIPTION android:text Sets text of the Textview android:id Gives a unique ID to the Textview android:cursorVisible Use this attribute to make cursor visible or invisible. Default value is visible. android:drawableBottom Sets images or other graphic assets to below of the Textview. android:drawableEnd Sets images or other graphic assets to end of Textview. android:drawableLeft Sets images or other graphic assets to left of Textview. android:drawablePadding Sets padding to the drawable(images or other graphic assets) in the Textview. android:autoLink This attribute is used to automatically detect url or emails and show it as clickable link. android:autoText Automatically correct spelling errors in text of the Textview. android:capitalize It automatically capitalize whatever the user types in the Textview. android:drawableRight Sets drawables to right of text in the Textview. android:drawableStart Sets drawables to start of text in the Textview. android:drawableTop Sets drawables to top of text in the Textview. android:ellipsize Use this attribute when you want text to be ellipsized if it is longer than the Textview width. android:ems Sets width of the Textview in ems. android:gravity We can align text of the Textview vertically or horizontally or both. android:height Use to set height of the Textview. android:hint Use to show hint when there is no text. android:inputType Use to set input type of the Textview. It can be Number, Password, Phone etc. android:lines Use to set height of the Textview by number of lines. android:maxHeight Sets maximum height of the Textview. android:minHeight Sets minimum height of the Textview. android:maxLength Sets maximum character length of the Textview. android:maxLines Sets maximum lines Textview can have. android:minLines Sets minimum lines Textview can have. android:maxWidth Sets maximum width Textview can have. android:minWidth Sets minimum lines Textview can have. android:textAllCaps Show all texts of the Textview in capital letters. android:textColor Sets color of the text. android:textSize Sets font size of the text. android:textStyle Sets style of the text. For example, bold, italic, bolditalic. android:typeface Sets typeface or font of the text. For example, normal, sans, serif etc android:width Sets width of the TextView.
  • 37. Java Code  TextView textView = (TextView) findViewById(R.id.textView); textView.setText("Android"); //set text for text view  textView.setTextSize(20);  textView.setBackgroundColor(Color.BLACK);//set background color T.ABIRAMI/KEC 37
  • 38. EditText  It is a user interface control  It is used to allow the user to enter or modify the text. Package Stru.. java.lang.Object ↳android.view.View ↳android.widget.TextView ↳android.widget.EditText T.ABIRAMI/KEC 38
  • 39. EditText :Attributes Inherited from TextView Class <EditText android:id="@+id/txtSub" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Subject" android:inputType="text"/> T.ABIRAMI/KEC 39
  • 40. EditText Attributes Attribute Description android:id It is used to uniquely identify the control android:gravity It is used to specify how to align the text like left, right, center, top, etc. android:text It is used to set the text. android:hint It is used to display the hint text when text is empty android:textColor It is used to change the color of the text. android:textColorHint It is used to change the text color of hint text. android:textSize It is used to specify the size of the text. android:textStyle It is used to change the style (bold, italic, bolditalic) of text. android:background It is used to set the background color for edit text control android:ems It is used to make the textview be exactly this many ems wide. android:width It makes the TextView be exactly this many pixels wide. android:height It makes the TextView be exactly this many pixels tall. android:maxWidth It is used to make the TextView be at most this many pixels wide. android:minWidth It is used to make the TextView be at least this many pixels wide. android:textAllCaps It is used to present the text in all CAPS android:typeface It is used to specify the Typeface (normal, sans, serif, monospace) for the text. android:textColorHighlight It is used to change the color of text selection highlight. android:inputType It is used to specify the type of text being placed in text fields. android:fontFamily It is used to specify the fontFamily for the text. android:editable If we set false, EditText won't allow us to enter or modify the text T.ABIRAMI/KEC 40
  • 41.  public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EditText et = (EditText) findViewById(R.id.txtSub); String name = et.getText().toString(); } } T.ABIRAMI/KEC 41 EditText simpleEditText = (EditText) findViewById(R.id.et_simple); String strValue = simpleEditText.getText().toString();
  • 42. Validating your Text if (name.getText().toString().isEmpty()|| password.getText().toString().isEmpty() || email.getText().toString().isEmpty() || dob.getText().toString().isEmpty() || phoneno.getText().toString().isEmpty()) { result.setText("Please Fill All the Details") } else { result.setText(name.getText().toString() + password.getText().toString() + email.getText().toString() + dob.getText().toString() + phoneno.getText().toString()) } T.ABIRAMI/KEC 42