Android Quiz App Tutorial



Similar documents
Tutorial #1. Android Application Development Advanced Hello World App

ANDROID APP DEVELOPMENT: AN INTRODUCTION CSCI /19/14 HANNAH MILLER

Developing an Android App. CSC207 Fall 2014

Introduction to Android Development. Daniel Rodrigues, Buuna 2014

By sending messages into a queue, we can time these messages to exit the cue and call specific functions.

Android Development Introduction CS314

MAP524/DPS924 MOBILE APP DEVELOPMENT (ANDROID) MIDTERM TEST OCTOBER 2013 STUDENT NAME STUDENT NUMBER

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Android Application Development. Yevheniy Dzezhyts

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Getting Started: Creating a Simple App

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Android App Development Lloyd Hasson 2015 CONTENTS. Web-Based Method: Codenvy. Sponsored by. Android App. Development

PHA Android Application Development

Android App Development. Rameel Sethi

Developing Android Apps: Part 1

How to Create an Android Application using Eclipse on Windows 7

Software Environments of Smartphone Applications

Mobile Application Development

Building Your First App

Localization and Resources

Mobile Application Frameworks and Services

ADITION Android Ad SDK Integration Guide for App Developers

Orders.java. ArrayList of Drinks as they are ordered. Functions to calculate statistics on Drinks

Developing NFC Applications on the Android Platform. The Definitive Resource

Android Programming Basics

Presenting Android Development in the CS Curriculum

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

Create Your Own Android App Tools Using ArcGIS Runtime SDK for Android

MMI 2: Mobile Human- Computer Interaction Android

HERE SDK for Android. Developer's Guide. Hybrid Plus Version 2.1

Getting Started With Android

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Jordan Jozwiak November 13, 2011

SPELL Tabs Evaluation Version

Android Mobile App Building Tutorial

Microsoft Expression Web Quickstart Guide

Blueball First Class Sandvox Designs v2.0 Works with Sandvox 2+ only!

Setting Up Your Android Development Environment. For Mac OS X (10.6.8) v1.0. By GoNorthWest. 3 April 2012

Android Development Tutorial

Dreamweaver and Fireworks MX Integration Brian Hogan

Creating an with Constant Contact. A step-by-step guide

Recreate your Newsletter Content and Layout within Informz (Workshop) Monica Capogna and Dan Reade. Exercise: Creating two types of Story Layouts

Learning Material Design

Skills and Topics for TeenCoder: Android Programming

Android UI Design. Android UI Design

Automatically Scaling Android Apps For Multiple Screens

Staying Organized with the Outlook Journal

Generate Android App

2. Click the download button for your operating system (Windows, Mac, or Linux).

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

A software stack for mobile devices:

HERE SDK for Android. Developer's Guide. Online Version 2.1

Android Development. Marc Mc Loughlin

Xamarin Android Application Development

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

How To Avoid Spam On Mailchimp

Search help. More on Office.com: images templates

Android Tutorial. Larry Walters OOSE Fall 2011

Chapter 9: Customize! Navigating with Tabs on a Tablet App

What is Android? originally purchased from Android, Inc. in 2005

IOIO for Android Beginners Guide Introduction

MICROSOFT OUTLOOK 2010 READ, ORGANIZE, SEND AND RESPONSE S

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

Microsoft Migrating to PowerPoint 2010 from PowerPoint 2003

RIT Message Center Compose and Send Messages

ADT Plugin for Eclipse

Umbraco Content Management System (CMS) User Guide

How to Build a SharePoint Website

Create and Print Your Own Greeting Cards

Mobile Apps with App Inventor

Using Karel with Eclipse

MS Excel Template Building and Mapping for Neat 5

Microsoft PowerPoint 2010 Handout

Hypercosm. Studio.

Android: Setup Hello, World: Android Edition. due by noon ET on Wed 2/22. Ingredients.

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Icons: 1024x1024, 512x512, 180x180, 120x120, 114x114, 80x80, 60x60, 58x58, 57x57, 40x40, 29x29

Using the Adventist Framework with your netadventist Site

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

How to create PDF maps, pdf layer maps and pdf maps with attributes using ArcGIS. Lynne W Fielding, GISP Town of Westwood

Wakanda Studio Features

getting started with box 1. What is box? 2. Creating an account 3. box functions

About XML in InDesign

Software Application Tutorial

Adobe Illustrator CS6. Illustrating Innovative Web Design

Frog VLE Update. Latest Features and Enhancements. September 2014

Writer Guide. Chapter 15 Using Forms in Writer

Honoring a Tradition of Simplicity. The Foundation. Getting Started

Module One: Getting Started Opening Outlook Setting Up Outlook for the First Time Understanding the Interface...

Level 13: Creating Yes / No Player Options

Microsoft PowerPoint 2010 Templates and Slide Masters (Level 3)

Intro to Android Development 2. Accessibility Capstone Nov 23, 2010

Creating an with Constant Contact. A step-by-step guide

SmallBiz Dynamic Theme User Guide

WebSite Tonight. Getting Started Guide. Getting Your Personal Website Online in One Night. WebSite Tonight // A Wedding Website

13 Managing Devices. Your computer is an assembly of many components from different manufacturers. LESSON OBJECTIVES

Exporting an image from Sibelius to Microsoft Word

Lab 1 (Reading Sensors & The Android API) Week 3

Transcription:

Step 1: Define a RelativeLayout Android Quiz App Tutorial Create a new android application and use the default settings. You will have a base app that uses a relative layout already.

A RelativeLayout is a flexible layout that allows you to organize UI elements in relation to one another, making it particularly useful for developers who need fine-grained control over the exact positioning of their UI components. Step 2: Designing for Multiple Screens: Background Image As an open source operating system, Android crops up on all sorts of devices, and is the OS of choice for many different manufacturers it s no longer even restricted to smartphones! This presents both exciting opportunities and headache-inducing challenges for Android developers. When developing your UI, keep in mind that your app needs to display correctly across as many devices as possible. While designing for multiple screens is too broad a topic for this tutorial, as a starting point you should provide alternate versions of every image used in your app. These alternate images should be optimized for screens with different pixel densities. When your app launches, Android will automatically load the correct image based on the device s display characteristics.

Open the res folder and you will see five drawable folders that Eclipse generates by default: drawable-ldpi drawable-mdpi drawable-hdpi drawable-xhdpi drawable-xxhdpi These folders target screens with different pixel densities, following a 3:4:6:8 scaling ratio (for example, if drawable-ldpi contains an image of 36 x 36 pixels, then drawable-mdpi should contain an image of 48 x 48 pixels, and so on). Create four versions of your background image based on this ratio, and drag each version into the appropriate folder. Add the background image to RelativeLayout using the android:background attribute, referring to the image resource as you would any drawable object: android:background="@drawable/background" The layout should not look something like this:

Run your app and let s see what we have so far. Hopefully your screen looks something like this: Step 3: Creating ImageButtons

The first step of creating an ImageButton is to add the required images to your project. Again, because you want your device to display correctly across a range of screens, you should provide four versions of each image. We ll start with the 2003 button, so drag and drop the five versions of your 2003 image into the corresponding folders. ImageButtons are created using the ImageButton tag followed by the usual height/width attributes, and some RelativeLayout-specific alignment attributes. Create your first ImageButton and tweak the alignment until you re happy with how it s positioned. <ImageButton android:id="@+id/imagebutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true"

android:src="@drawable/button2003" /> Check how this appears in the emulator. Repeat this process for the other four buttons. This is a good opportunity to experiment with the various RelativeLayout attributes As you fine-tune your layout, you may find it useful to keep the emulator open, switching between it, the graphical layout editor and your XML. Here s the finished Activity_Main.xml layout file:

<RelativeLayout 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" android:background="@drawable/background" > <ImageButton android:id="@+id/imagebutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:src="@drawable/button2003" /> <ImageButton android:id="@+id/imagebutton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/imagebutton1" android:layout_centerhorizontal="true" android:src="@drawable/button2004" /> <ImageButton android:id="@+id/imagebutton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/imagebutton2" android:layout_centerhorizontal="true" android:src="@drawable/button2005" /> <ImageButton android:id="@+id/imagebutton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/imagebutton3" android:layout_centerhorizontal="true" android:src="@drawable/button2006" /> </RelativeLayout> Run your app again and make sure you like the look of the layout so far:

The buttons may be displaying correctly in the emulator, but Eclipse is probably throwing multiple Missing contentdescription attribute on image errors. Step 4: Making Your App Accessible The ContentDescrition attribute makes applications more accessible to users who cannot easily consume graphical content, by providing an alternate text description. This description can be used by screen readers and similar accessibility tools.

The first step is to define some new string resources. Strings are defined in the res/layout/strings.xml file, so open it and switch to the strings.xml tab if necessary. String resources are created with the following syntax: <string name="name">text to display</string> Define a string for the ContentDescription of each ImageButton as follows: <string name="button2003">answer 2003</string> <string name="button2004">answer 2004</string> <string name="button2005">answer 2005</string> <string name="button2006">answer 2006</string> Return to your activity_main.xml file and add a ContentDescription attribute to each of the ImageButtons as follows: Add to each button: android:contentdescription="@string/button2003 Do this for all of the buttons and change the names to the correct button images. Step 5: Creating Stylish Text In reality, it s unlikely you ll cease developing an app at Version 1.0, as you cook up new content and release fixes for any pesky bugs that users discover. Therefore, it s handy if people can tell at a glance what version of your app they re running. The easiest way to do this is with a TextView. Open the strings.xml file and define the current version number as a string: <string name="version">version 1.0</string> You can quickly create a TextView that calls @string/version but Android s default text style isn t particularly appealing. Thankfully,

TextView has a range of attributes that can give boring old text some style. In this tutorial we ll use the following: android:textcolor sets the color of your text. It can either be defined as a string resource, or as a color value. android:textsize sets the text size, which can be given either as px (pixels) sp (scaled pixels) dp (density-independent pixels) in (inches) or mm (millimeters) android:textstyle either italic or bold. Open your Activity_Main.xml file and create your TextView, add some style attributes, and then reference the Version string: <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_marginleft="26dp" android:paddingbottom="5dp" android:text="@string/version" android:textcolor="#f7f9f6" android:textsize="13dp" android:textstyle="italic" /> You should now see the version information in the lower part of the screen as follows:

This works, but if you re planning to re-use this set of attributes elsewhere then you should define it as a custom Style. A style is a time-saving collection of properties (in this case font color, font size, and the italic style) that specifies the appearance of a view, or even an entire application. You ll often hear styles and themes mentioned in a similar context. Essentially, the only difference between a style and a theme is their scope: styles that are applied to activities become themes. To define a custom style: 1. Open the res/values/styles.xml file, ensure it has opening and closing resource tags, and give your style a unique name and define all the attributes that belong to this style: <style name="versionfont"> <item name="android:textcolor">#f7f9f6</item> <item name="android:textsize">13dp</item> <item name="android:textstyle">italic</item> </style> Applying this custom style to your TextView is easy, simply replace all the attributes defined by the VersionFont style, with: style="@style/versionfont". For example:

<TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_marginleft="26dp" android:paddingbottom="5dp" android:text="@string/version" style="@style/versionfont" /> This custom style isn t defined in the Android namespace, which is why we don t need to include an android: reference. Both of these methods are valid ways of styling text, but keep in mind that a custom style can speed up the coding process if you re going to re-use the same collection of attributes across your application. Step 6: Making Your App Interactive Your UI may be finished, but there s one final step: letting the user know whether they ve selected the correct answer. The easiest way to make buttons tappable is by implementing the android:onclick property for each button. We ll start by adding it to the first button: Add for each botton: android:onclick="onclick2003" Change the name of the event to match each of the years. The name of the onclick method must correspond to a public method in the MainActivity.Java file. Now we need to specify the behavior that onclick2003 triggers. A straightforward way of telling the user they ve got the question wrong, is with a toast notification. Add the following method to MainActivity.java:

public void onclick2003 (View view) { Toast.makeText(this, "Wrong! Try again", Toast.LENGTH_SHORT).show(); } Run this updated code in the emulator and get clicking to check your toast is firing properly. Success! Add the onclick method for the other three buttons and create corresponding public methods in your Activity, with appropriate messages attached. Once you ve finished, boot up the emulator and have a click around to check everything s working okay.

The finished method set looks like this: public void onclick2003 (View view) { Toast.makeText(this, "Wrong! Try again", Toast.LENGTH_SHORT).show(); } public void onclick2004 (View view) { Toast.makeText(this, "Wrong! Try again", Toast.LENGTH_SHORT).show(); }

public void onclick2005 (View view) { Toast.makeText(this, "Yes! Well done :)", Toast.LENGTH_SHORT).show(); } public void onclick2006 (View view) { Toast.makeText(this, "Wrong! Try again", Toast.LENGTH_SHORT).show(); } Conclusion Over the course of this tutorial you ve learned the essentials of Android UI design and created a simple, but effective UI that has some working functionality to boot! Try applying some of these techniques to your own Android projects, to ensure your UI doesn t let your app down.