SlideShare a Scribd company logo
1 of 15
07.1. Event Handling
Oum Saokosal
Master of Engineering in Information Systems, South Korea
855-12-252-752
oum_saokosal@yahoo.com
Agenda
• XML-based Event Handling
• Java-based Event Handling
• More Event Listeners
XML-based Event Handling
XML-based Event Handling (1)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:text="Show Me!"
android:id="@+id/btnShowMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showMe"
/>
</LinearLayout>
1
XML-based Event Handling (2)
package com.kosalab;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class WidgetContainer extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventhandling);
}
public void showMe(View v){
Toast.makeText(this, "This event invoked from XML.",
Toast.LENGTH_SHORT).show();
}
}
2
Java-based Event Handling
Java-based Event Handling (1)
?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:text="Show Me!"
android:id="@+id/btnShowMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
1
Java-based Event Handling (2)
public class WidgetContainer extends Activity
implements OnClickListener{
Button btn;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventhandling);
btn = (Button)findViewById(R.id.btnShowMe);
btn.setOnClickListener(this);
}
public void onClick(View v) {
Toast.makeText(this, "It's Toast Message! It appears
shortly.“, Toast.LENGTH_SHORT).show();
}
}
3
4
5
2
Java-based Event Handling –
Another Example
public class WidgetContainer extends Activity implements
OnClickListener, OnLongClickListener{
Button btn;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventhandling);
btn = (Button)findViewById(R.id.btnShowMe);
btn.setOnClickListener(this);
btn.setOnLongClickListener(this);
}
public void onClick(View v) {
Toast.makeText(this, “Short click!“,
Toast.LENGTH_SHORT).show();
}
public boolean onLongClick(View v) {
Toast.makeText(this, “Long click!",
Toast.LENGTH_SHORT).show();
return true;
}
}
1
2
3
4
onLongClick() – return true/false
public boolean onLongClick(View v) {
Toast.makeText(this, “Long click!",
Toast.LENGTH_SHORT).show();
return true;
}
Note:
return true: show only the longClick.
return false: show both longclick and then
short click.
More Event Listeners
• onFocusChange()
From View.OnFocusChangeListener. This is called when the user navigates onto or
away from the item, using the navigation-keys or trackball.
• onKey()
From View.OnKeyListener. This is called when the user is focused on the item and
presses or releases a key on the device.
• onTouch()
From View.OnTouchListener. This is called when the user performs an action
qualified as a touch event, including a press, a release, or any movement gesture
on the screen (within the bounds of the item).
• onCreateContextMenu()
From View.OnCreateContextMenuListener. This is called when a Context Menu is
being built (as the result of a sustained "long click").
Go on to the next slide

More Related Content

What's hot

React Native Error Reporting with Sentry
React Native Error Reporting with SentryReact Native Error Reporting with Sentry
React Native Error Reporting with SentryAmin Yazdani Salekdeh
 
Обзор Android M
Обзор Android MОбзор Android M
Обзор Android MWOX APP
 
Animation And Testing In AngularJS
Animation And Testing In AngularJSAnimation And Testing In AngularJS
Animation And Testing In AngularJSEdureka!
 
AngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW FrameworkAngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW FrameworkEdureka!
 
4.preference management
4.preference management 4.preference management
4.preference management maamir farooq
 
Angular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page ApplicationAngular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page ApplicationEdureka!
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...Akira Hatsune
 
Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020Microsoft 365 Developer
 
2010 08-26-smart-architecture
2010 08-26-smart-architecture2010 08-26-smart-architecture
2010 08-26-smart-architectureCHIP
 
Live Demo : Trending Angular JS Featues
Live Demo : Trending Angular JS FeatuesLive Demo : Trending Angular JS Featues
Live Demo : Trending Angular JS FeatuesEdureka!
 
Webinar on Angular JS titled 'Develop Responsive Single Page Application'
Webinar on Angular JS titled 'Develop Responsive Single Page Application'Webinar on Angular JS titled 'Develop Responsive Single Page Application'
Webinar on Angular JS titled 'Develop Responsive Single Page Application'Edureka!
 
Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...
Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...
Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...Infinum
 
Share kmu itbz_20181106
Share kmu itbz_20181106Share kmu itbz_20181106
Share kmu itbz_20181106DongHyun Gang
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in androidInnovationM
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
Salesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on TrainingSalesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on TrainingSunil kumar
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10Chris Schalk
 

What's hot (20)

React Native Error Reporting with Sentry
React Native Error Reporting with SentryReact Native Error Reporting with Sentry
React Native Error Reporting with Sentry
 
Обзор Android M
Обзор Android MОбзор Android M
Обзор Android M
 
Animation And Testing In AngularJS
Animation And Testing In AngularJSAnimation And Testing In AngularJS
Animation And Testing In AngularJS
 
AngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW FrameworkAngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW Framework
 
4.preference management
4.preference management 4.preference management
4.preference management
 
Angular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page ApplicationAngular JS - Develop Responsive Single Page Application
Angular JS - Develop Responsive Single Page Application
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
 
Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020
 
Create twitter-ios-app
Create twitter-ios-appCreate twitter-ios-app
Create twitter-ios-app
 
2010 08-26-smart-architecture
2010 08-26-smart-architecture2010 08-26-smart-architecture
2010 08-26-smart-architecture
 
Live Demo : Trending Angular JS Featues
Live Demo : Trending Angular JS FeatuesLive Demo : Trending Angular JS Featues
Live Demo : Trending Angular JS Featues
 
Services
ServicesServices
Services
 
Webinar on Angular JS titled 'Develop Responsive Single Page Application'
Webinar on Angular JS titled 'Develop Responsive Single Page Application'Webinar on Angular JS titled 'Develop Responsive Single Page Application'
Webinar on Angular JS titled 'Develop Responsive Single Page Application'
 
Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...
Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...
Infinum Android Talks #14 - Data binding to the rescue... or not (?) by Krist...
 
Share kmu itbz_20181106
Share kmu itbz_20181106Share kmu itbz_20181106
Share kmu itbz_20181106
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Salesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on TrainingSalesforce Lightning Data Services- Hands on Training
Salesforce Lightning Data Services- Hands on Training
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10
 

Viewers also liked

Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Androidma-polimi
 
Understanding Android Handling of Touch Events
Understanding Android Handling of Touch EventsUnderstanding Android Handling of Touch Events
Understanding Android Handling of Touch Eventsjensmohr
 
10.1. Android Audio
10.1. Android Audio10.1. Android Audio
10.1. Android AudioOum Saokosal
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event HandlingNikmesoft Ltd
 
04. Review OOP with Java
04. Review OOP with Java04. Review OOP with Java
04. Review OOP with JavaOum Saokosal
 
10.3 Android Video
10.3 Android Video10.3 Android Video
10.3 Android VideoOum Saokosal
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto CompleteOum Saokosal
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in androidOum Saokosal
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)Oum Saokosal
 
Java Programming - Polymorphism
Java Programming - PolymorphismJava Programming - Polymorphism
Java Programming - PolymorphismOum Saokosal
 
Objected-Oriented Programming with Java
Objected-Oriented Programming with JavaObjected-Oriented Programming with Java
Objected-Oriented Programming with JavaOum Saokosal
 
10.2 Android Audio with SD Card
10.2 Android Audio with SD Card10.2 Android Audio with SD Card
10.2 Android Audio with SD CardOum Saokosal
 
Java Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract ClassJava Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract ClassOum Saokosal
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - InheritanceOum Saokosal
 
Database Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS AccessDatabase Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS AccessOum Saokosal
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)Oum Saokosal
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Oum Saokosal
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceOum Saokosal
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFOum Saokosal
 

Viewers also liked (20)

Event Handling
Event HandlingEvent Handling
Event Handling
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
Understanding Android Handling of Touch Events
Understanding Android Handling of Touch EventsUnderstanding Android Handling of Touch Events
Understanding Android Handling of Touch Events
 
10.1. Android Audio
10.1. Android Audio10.1. Android Audio
10.1. Android Audio
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event Handling
 
04. Review OOP with Java
04. Review OOP with Java04. Review OOP with Java
04. Review OOP with Java
 
10.3 Android Video
10.3 Android Video10.3 Android Video
10.3 Android Video
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)
 
Java Programming - Polymorphism
Java Programming - PolymorphismJava Programming - Polymorphism
Java Programming - Polymorphism
 
Objected-Oriented Programming with Java
Objected-Oriented Programming with JavaObjected-Oriented Programming with Java
Objected-Oriented Programming with Java
 
10.2 Android Audio with SD Card
10.2 Android Audio with SD Card10.2 Android Audio with SD Card
10.2 Android Audio with SD Card
 
Java Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract ClassJava Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract Class
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - Inheritance
 
Database Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS AccessDatabase Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS Access
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 

Similar to 07.1. Android Even Handling

Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
HTML5 on Mobile
HTML5 on MobileHTML5 on Mobile
HTML5 on MobileAdam Lu
 
2. file internal memory
2. file internal memory2. file internal memory
2. file internal memorymaamir farooq
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...olrandir
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Gustavo Fuentes Zurita
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Gustavo Fuentes Zurita
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_programEyad Almasri
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgetsSiva Kumar reddy Vasipally
 
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
"Progressive Web Apps" by Riza Fahmi	(Hacktiv8)"Progressive Web Apps" by Riza Fahmi	(Hacktiv8)
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)Tech in Asia ID
 
Progressive Web Apps. What, why and how
Progressive Web Apps. What, why and howProgressive Web Apps. What, why and how
Progressive Web Apps. What, why and howRiza Fahmi
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011sullis
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivitiesmaamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activitiesmaamir farooq
 
Android studio
Android studioAndroid studio
Android studioAndri Yabu
 
Introduction to Android Programming
Introduction to Android ProgrammingIntroduction to Android Programming
Introduction to Android ProgrammingRaveendra R
 
Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)Adam Lu
 
Fragments: Why, How, What For?
Fragments: Why, How, What For?Fragments: Why, How, What For?
Fragments: Why, How, What For?Brenda Cook
 

Similar to 07.1. Android Even Handling (20)

Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
HTML5 on Mobile
HTML5 on MobileHTML5 on Mobile
HTML5 on Mobile
 
2. file internal memory
2. file internal memory2. file internal memory
2. file internal memory
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9
 
Android
AndroidAndroid
Android
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
 
06 UI Layout
06 UI Layout06 UI Layout
06 UI Layout
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
 
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
"Progressive Web Apps" by Riza Fahmi	(Hacktiv8)"Progressive Web Apps" by Riza Fahmi	(Hacktiv8)
"Progressive Web Apps" by Riza Fahmi (Hacktiv8)
 
Progressive Web Apps. What, why and how
Progressive Web Apps. What, why and howProgressive Web Apps. What, why and how
Progressive Web Apps. What, why and how
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
 
Android studio
Android studioAndroid studio
Android studio
 
Intro to Android Programming
Intro to Android ProgrammingIntro to Android Programming
Intro to Android Programming
 
Introduction to Android Programming
Introduction to Android ProgrammingIntroduction to Android Programming
Introduction to Android Programming
 
Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)
 
Fragments: Why, How, What For?
Fragments: Why, How, What For?Fragments: Why, How, What For?
Fragments: Why, How, What For?
 

Recently uploaded

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 

Recently uploaded (20)

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 

07.1. Android Even Handling

  • 1. 07.1. Event Handling Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 oum_saokosal@yahoo.com
  • 2. Agenda • XML-based Event Handling • Java-based Event Handling • More Event Listeners
  • 4. XML-based Event Handling (1) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="Show Me!" android:id="@+id/btnShowMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="showMe" /> </LinearLayout> 1
  • 5. XML-based Event Handling (2) package com.kosalab; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class WidgetContainer extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eventhandling); } public void showMe(View v){ Toast.makeText(this, "This event invoked from XML.", Toast.LENGTH_SHORT).show(); } } 2
  • 6.
  • 8. Java-based Event Handling (1) ?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="Show Me!" android:id="@+id/btnShowMe" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> 1
  • 9. Java-based Event Handling (2) public class WidgetContainer extends Activity implements OnClickListener{ Button btn; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eventhandling); btn = (Button)findViewById(R.id.btnShowMe); btn.setOnClickListener(this); } public void onClick(View v) { Toast.makeText(this, "It's Toast Message! It appears shortly.“, Toast.LENGTH_SHORT).show(); } } 3 4 5 2
  • 10.
  • 11. Java-based Event Handling – Another Example
  • 12. public class WidgetContainer extends Activity implements OnClickListener, OnLongClickListener{ Button btn; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eventhandling); btn = (Button)findViewById(R.id.btnShowMe); btn.setOnClickListener(this); btn.setOnLongClickListener(this); } public void onClick(View v) { Toast.makeText(this, “Short click!“, Toast.LENGTH_SHORT).show(); } public boolean onLongClick(View v) { Toast.makeText(this, “Long click!", Toast.LENGTH_SHORT).show(); return true; } } 1 2 3 4
  • 13. onLongClick() – return true/false public boolean onLongClick(View v) { Toast.makeText(this, “Long click!", Toast.LENGTH_SHORT).show(); return true; } Note: return true: show only the longClick. return false: show both longclick and then short click.
  • 14. More Event Listeners • onFocusChange() From View.OnFocusChangeListener. This is called when the user navigates onto or away from the item, using the navigation-keys or trackball. • onKey() From View.OnKeyListener. This is called when the user is focused on the item and presses or releases a key on the device. • onTouch() From View.OnTouchListener. This is called when the user performs an action qualified as a touch event, including a press, a release, or any movement gesture on the screen (within the bounds of the item). • onCreateContextMenu() From View.OnCreateContextMenuListener. This is called when a Context Menu is being built (as the result of a sustained "long click").
  • 15. Go on to the next slide