Android Topics Custom ArrayAdapters Creating an Event Listener

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 6 Overview Programming Tutorial 3: Sending/Receiving SMS Messages.
Advertisements

Programming with Android: Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Chapter 6: Jam! Implementing Audio in Android Apps.
Unlocking Android Chapter 4.  Understanding activities and views  Exploring the Activity lifecycle  Working with resources  Defining the AndroidManifest.xml.
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Development (Basics)
App Development on Android. Contents  First Milestone  Second Milestone  Third Milestone  Last Milestone 
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Introducing the Sudoku Example
Chapter 2: Simplify! The Android User Interface
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 5: Investigate! Android Lists, Arrays,
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 7: Reveal! Displaying Pictures in a GridView.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Android Boot Camp for Developers Using Java, 3E
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Field Trip #32 Digital Alarm Clock By Keith Lynn.
User Interface Android Club Agenda Button OnClickListener OnLongClickListener ToggleButton Checkbox RatingBar AutoCompleteTextView.
Handling View Events. Open the *MainActivity.java* which is the Activity that hosts the layout in "activity_main.xml". The setContentView method inside.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Video Games list lab 6  At the end of this lab you will be expected to know:  What Views, View Groups, Layouts, and Widgets are and how they relate to.
MOBILE COMPUTING D10K-7D02 MC05: Android UI Design Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
Multimedia Capture & storage. Introduction A rich set of API for recording of audio & video. A developer has two choices  launch the built-in app using.
CS378 - Mobile Computing Audio.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
Building User Interfaces Basic Applications
User Interface Layout Interaction. EventsEvent Handlers/Listeners Interacting with a user.
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Java for android Development Nasrullah Khan. Using instanceof in Android Development the classes such as Button, TextView, and CheckBox, which represent.
Cosc 5/4730 Support design library. Support Design library Adds (API 9+) back support to a number of 5.0 lollipop widgets and material design pieces –
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Chapter 2: Simplify! The Android User Interface
Android Application Audio 1.
CS499 – Mobile Application Development
Further android gui programming
Mobile Application Development BSCS-7 Lecture # 9
Android – Event Handling
Introduction to Event-Driven Programming
Mobile Application Development BSCS-7 Lecture # 8
Creation of an Android App By Keith Lynn
Chapter 3: Coding the GUI Programmatically, Layout Managers
Android Programming Lecture 9
Android Programming Lecture 6
Introduction to Computing Using Java
Android ListView Demo.
ANDROID LISTS.
CS5103 Software Engineering
Android Lists and Fragments
Cannon Game App Android How to Program
Building User Interfaces Basic Applications
Android Topics Android Activity Lifecycle and Experiment Toast
Android Topics Custom ArrayAdapters
Android Developer Fundamentals V2
Android Topics Asynchronous Callsbacks
Android Topics Limited Resources and why we need to consider them.
HNDIT2417 Mobile Application Development
Constructors, GUI’s(Using Swing) and ActionListner
Android Developer Fundamentals V2
ListView ? BaseAdapter ?.
Mobile Programmming Dr. Mohsin Ali Memon.
CA16R405 - Mobile Application Development (Theory)
Presentation transcript:

Android Topics Custom ArrayAdapters Creating an Event Listener In-class App: Contact App using our own custom ArrayAdapter Lab 5 Part 4. OnClickListener Interface. Creating an Event Listener. Complete the App from Lab 5 Part 4.

In-class App This app will help Moquelumnan language students practice their number (1-10) skills. Each number includes an image, the written English name, the numeric value, and an audio sound that will play when the user taps directly on the list item. The activity_number layout must produce a scrollable listing without using a ScrollView. Use a ListView powered by a custom ArrayAdapter. The audio and image files can be downloaded from the website.

Explore OnClickListener Question: What did you find?

Explore OnClickListener Question: What did you find? Answer: OnClickListener is an interface. onClick() is the abstract method. NOTE: Implementation for abstract methods is intentionally left blank so that a developer wanting to use the interface can provide their own specific instructions for it.

Review of Classes and Interface Concrete class: if you come across a concrete class in Android you can use it right away. Abstract class: This is a partially implemented class and it contains states and some methods that are fully implemented. Some methods are left abstract so that coders can define the behavior as they choose. Interface: If you come across an interface, you need to provide code for all the abstract methods. Think of these elements as a continuum where an interface is not implemented at all, an abstract class is partially implemented, and a concrete class is fully implemented.

Concrete Class public class TextView{ String mText; int mTextColorID; void setText( String str){ mText = str; } void setTextColor ( int color) { mTextColorID = color; …. Concrete Class

Abstract Class public abstract class ViewGroup { int nChildCount; void addView (View view){ addViewInternal (view, -1); nChildCount++; } void removeView (View view) { removeViewInternal (view); nChildCount--; void onLayout() ; …. Abstract Class

Interface public interface OnClickListener { void onClick (View view); }

Creating an Event Listener As a mobile developer, you will need to set up event listeners for the input events you want to handle. In a simple app, you can easily utilize the onClick property for a given view in your layout.

Explore onClick The onClick() method is a callback method. onClick() is automatically invoked when a registered event is triggered. onClick() has exactly one parameter, the View object being clicked on. NOTE: Remember, for an interface, you need to provide for all the abstract methods.

How to set up an Event Listener?

In MainActivity.java 3. Define the event listener inline (and the custom behavior for then the event is triggered. 1. Attach the listener to a View. 2. Create new object instance of event listener. buttonView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(view.getContext(), “Hello”, Toast.LENGTH_SHORT).show(); } });

Numbers App: Event Listener In the Numbers App, it is less clear which View has triggered a listener event. Research OnItemClickListener. What did you find?

OnItemClickListener is an interface definition for a callback to be invoked when an item in an AdapterView has been clicked. There is only one public method. This method is a callback method, onItemClick().

Quick Review Similarities setOnClickListener vs. setOnItemClickListener: OnClickListener vs OnItemClickListener: onClick vs onItemClick: Both of these register a listener that will trigger an event. Both are interfaces for abstract listener events. Both are abstract methods for handling a listener event.

Quick Review Differences onItemClick: A Callback method to be invoked when an item in an AdapterView has been clicked. onClick: A Callback method to be invoked when a View within an Activity layout has been clicked.

Tasks for implementing an Event Listener for ListView+ArrayAdapter: Register a listener using setOnItemClickListener. Implement onItemClick() from OnItemClickListener(). Call getItem (position) to access the object clicked. onItemClick() parameters:

// CREATE AN ADAPTER AND LOAD IT WITH DATA OBJECTS // ATTACH THE LISTVIEW TO THE ADAPTER NumberWordAdapter itemsAdapter = new NumberWordAdapter(this, words); listView.setAdapter(itemsAdapter); //CREATE AN EVENT LISTENER TO RESPOND TO A CLICKED LISTVIEW ITEM listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String myWord = words.get(position).name); } }); } AdapterView where the click happened. The view within the AdapterView that was clicked. The position of the view in the adapter. The row id of the item that was clicked

Experiment with the Numbers App Experiment with the Numbers App. Display a Toast containing the audio id of a clicked ListView item.

Review MediaPlayer Examine MediaPlayer documentation Question: What are the different states that we can transition between as the media player plays a sound file?

The media player object is initially in an idle state The media player object is initially in an idle state. It is sitting there Idle, waiting for instructions. In the Prepared state, a song has been assigned. The media player is preparing to play a certain audio file. No sounds are made. In Started state the media player is playing an audio file. Pause state will produce a pause. From the Paused state can return to Started state to resume where an audio was left off . Stop can halt the audio. Once stop the media player has stopped, it can’t be resume. It needs to enter the Prepared state.

Handling Touch Events on a ListView

Complete the Moquelumnan language app.