SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Animation And Testing In AngularJS
Animation And Testing In AngularJSAnimation And Testing In AngularJS
Animation And Testing In AngularJS
Edureka!
 
2010 08-26-smart-architecture
2010 08-26-smart-architecture2010 08-26-smart-architecture
2010 08-26-smart-architecture
CHIP
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10
Chris Schalk
 

Was ist angesagt? (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
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie 07.1. Android Even Handling

Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9
Gustavo Fuentes Zurita
 
Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9Androidoscon20080721 1216843094441821-9
Androidoscon20080721 1216843094441821-9
Gustavo Fuentes Zurita
 

Ähnlich wie 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?
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Kürzlich hochgeladen (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

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