Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

Similar documents
University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

Mobile Programming Lecture 1. Getting Started

Lab Android Development Environment

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

Android HelloWorld - Example. Tushar B. Kute,

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

android-espresso #androidespresso

CS 234/334 Lab 1: Android Jump Start

Getting Started With Android Feature Flags

Lab 1: Getting Started With Android Programming

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

Eventually, you'll be returned to the AVD Manager. From there, you'll see your new device.

Building MyFirstApp Android Application Step by Step. Sang Shin Learn with Passion!

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

(Refer Slide Time: 1:12)

(Refer Slide Time: 1:07)

Hello World. Lesson 1. Create your first Android. Android Developer Fundamentals. Android Developer Fundamentals

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (1 &2 of 3) Hello-Goodbye App Tutorial

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Google Maps Troubleshooting

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

This document providesanoverview ofthestepsrequired to implement an android app which will call the ACH android SDK.

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

Exercise 1: First Android App

ANDROID APPS (NOW WITH JELLY BEANS!) Jordan Jozwiak November 11, 2012

Assignment 1: Port & Starboard

Android Application Development. By : Shibaji Debnath

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Mobile Application Development

Introduction To Android

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

Android Tutorial: Part 3

Chapter 2 Welcome App

1. Implementation of Inheritance with objects, methods. 2. Implementing Interface in a simple java class. 3. To create java class with polymorphism

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (Part 1-2) Hello-Goodbye App Tutorial

Programming Mobile Applications with Android Lab1

Assistant Professor Computer Science. Introduction to Human-Computer Interaction

(Refer Slide Time: 0:48)

Lab 3. Accessing GSM Functions on an Android Smartphone

ConstraintLayouts in Android

Produced by. Mobile Application Development. Eamonn de Leastar

Lab 1 - Setting up the User s Profile UI

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Introduction to Android Development

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

Android Studio is google's official IDE(Integrated Development Environment) for Android Developers.

05. RecyclerView and Styles

BlackBerry Developer Global Tour. Android. Table of Contents

CS 403X Mobile and Ubiquitous Computing Lecture 3: Introduction to Android Programming Emmanuel Agu

ELET4133: Embedded Systems. Topic 15 Sensors

by- Salman A. Khan, Ishendra Agarwal,Prateek Sahu,Manas

Configuring the Android Manifest File

Wireless Vehicle Bus Adapter (WVA) Android Library Tutorial

Lab #1: A Quick Introduction to the Eclipse IDE

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Getting Started with Android Development Zebra Android Link-OS SDK Android Studio

Android Programming Lecture 2 9/7/2011

E-Blocks wifi controlled by an Android device

XML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.

Lifecycle Callbacks and Intents

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Introduction to Android Programming. Emmanuel Agu

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Android Workshop: Model View Controller ( MVC):

Hello World on the ATLYS Board. Building the Hardware

Open Lecture Mobile Programming. Command Line Tools

Fragments. Lecture 11

CS 4518 Mobile and Ubiquitous Computing Lecture 4: WebView (Part 2) Emmanuel Agu

Our First Android Application

Introduction to User Interface Elements in Android

UNDERSTANDING ACTIVITIES

EMBEDDED SYSTEMS PROGRAMMING Android NDK

Using Eclipse for Android Development

Fragments. Lecture 10

Creating mobile applications in Android Studio. Creating mobile applications in Android Studio

Mobile Image Processing

07. Menu and Dialog Box. DKU-MUST Mobile ICT Education Center

Mobile Programming Lecture 3. Resources, Selection, Activities, Intents

CS 4518 Mobile and Ubiquitous Computing Lecture 2: Introduction to Android Programming. Emmanuel Agu

Android UI Development

CE881: Mobile & Social Application Programming

INTRODUCTION TO ANDROID

After you create a new project you should be able to access the below windows:

Accessibility. Adding features to support users with impaired vision, mobility, or hearing


Programming Concepts and Skills. Creating an Android Project

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

Link-OS SDK for Xamarin README

Login with Amazon. Getting Started Guide for Android apps

Basic GUI elements - exercises

Introduction to Android

Tutorial on OpenCV for Android Setup

CS 528 Mobile and Ubiquitous Computing Lecture 1b: Introduction to Android. Emmanuel Agu

Developing Android Applications

Step 1 Turn on the device and log in with the password, PIN, or other passcode, if necessary.

Android Application Development Instructions

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

Tutorial on OpenCV for Android Setup

Transcription:

Hello World Lab Objectives: Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.xml What to Turn in: The lab evaluation form checked off and signed by your TA 1 Using Android Studio and the Android SDK for the First Time: On the lab machines there is a shortcut in the start menu called Android Studio. Click this shortcut to open the Android Studio. Or if you would like to use your personal computer for Android development then download the Android Studio from this site: http://developer.android.com/sdk/index.html Open Android Studio. It will ask you to select an Install type. Select Custom. This screen will pop up, then select the SDK location. 1

The SDK to use is under: C:\Android\sdk 2

Accept the terms and conditions, wait and then hit finish. Select Start a new Android Studio project 3

Configure your new project with the following properties. From here, follow the instructions detailed for adding an activity and starting your project. Enjoy! 4

Adding Layout Elements: 1. A new project folder with your Android application should be created. Now we will add elements to the user interface. 2. In your project folder go into res/layout/ and open the only XML file available. 3. Make sure that you have the graphical layout tab selected. You should now have a window showing your layout with a standard text field saying Hello world. 4. On the left hand side of the screen in the palette there is a Form Widgets section. Drag a button and drop it onto your activity layout. You may choose to customize your layout in any way that you see fit as long as it contains one button and one text view. 5. The text of the button is currently hard set in the XML file. However, Android has a much better way of organizing strings through the use of XML files. Open res/values/strings.xml. In the resources tab you will be able to add strings to the file. Add a string named button with the value Change Text. 6. In your activity s XML file, choose the activity_main.xml tab just below the editing window near the Graphical Layout tab, and change the android:text value for the button to "@string/button". Note: xml is case sensitive, so @string/button does make a difference. 5

Creating an onclick Listener: CPRE 388: Hello World 1. In order to give the button functionality you will have to specify a method to run once the button has been clicked. 2. Open the.java file found under the src folder and package. This file will be named the same as your project. 3. After the last method but before the end of the class add this method to be called on a button click: public void changetext(view view){ } Hint: You will need to import the View class. In Android Studio use the auto import feature. You can go to File -> Settings -> Editor -> General -> Auto Import -> Java and make the following changes: change Insert imports on paste value to All mark Add unambigious imports on the fly option as checked or You can press Alt + enter placing cursor on the line to auto import in android studio. 4. Now go back to your activity s XML file and choose the tab besides the Graphical Layout that displays the xml code. Here you will find a text representation of the button. 5. Within the button s declaration after <Button but before /> add this line: android:onclick="changetext" Note how the name matches the method that was just created. Using the android:onclick attribute for a button is one of the ways we can set its functionality. 6. We also need to give our TextView an id so we can get access to it programmatically later. Within the TextView s declaration after <TextView but before /> add this line: android:id="@+id/textview1" This value may already be included depending on your IDE s settings. If it is set it to match the value above. Making Messages Display: 1. Now we want to have the method actually do something. Add these variables to the beginning of the class. 6

private String[] messages; private Random random; You will need to import the Random class. 2. Also in the oncreate method (a method that is called whenever the layout is loaded) add these lines of code: protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } random = new Random(); messages = new String[10]; messages[0] = "Hello Dave!"; messages[1] = "These are not the Droids you're looking for."; messages[2] = "All your Androids are belong to us!"; messages[3] = "Thank you! \nbut our Android is in another castle."; messages[4] = "It's a Me! \nandroid!"; messages[5] = "Would you kindly press the button again?"; messages[6] = "It's dangerous to go alone, take this. \nthe screen doubles as a flashlight!"; messages[7] = "Hey! Look! Listen! \npress the button again!"; messages[8] = "Fus Ro Droid! \n unrelenting Android "; messages[9] = "The apple is a lie!"; and in the changetext method add these lines of code: public void changetext(view view){ TextView text = (TextView) findviewbyid(r.id.textview1); } text.settext(messages[random.nextint(10)]); Note: in Java, the only things can be put under class declaration are instance variables; anything else should always be contained by a method. Running Your First Android Application on an Android Device: If you are using a Nexus 7 device you will need to enable the developer options on the device before you can use Andriod Studio to install apps that you develop. Specifically for the Nexus 7, to enable the developer options go to Settings > About tablet and press the Build number 7 times. This will allow you to see the developer options in the Settings page. Go back to Settings then choose Developer options and enable USB debugging. You should now be able to run your application on the device. If you would like to get your personal Android device to work with a lab machine, please ask a TA for assistance. To use the build in Emulator: 1. Under the Run menu on the top of the window select Run + App name 7

2. There is a choose device option pops up, select Launch emulator 3. Then click ok, the emulator will start and your app will run automatically. Note: If you find the default Gradle Scripts were using the wrong version and causing build errors. To fix this, do these steps: 1. In the left pane select "Project" 2. Expand "Gradle Scripts" 3. Double-click on "build.gradle (Module: app)" 4. Replace "com.android.support:appcompat-v7:23.0.0" with "com.android.support:appcompat-v7:22.2.1" as shown below... dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' } Hello World Application Demo: If completed correctly, the app should display a TextView saying Hello World! and a button saying Change Text. When the button is pressed the text field should cycle randomly through a list of predetermined phrases. Part of this lab is based on creativity. Use your design skills to make this application more creative. Some examples include making the button an ImageButton, changing the background color, add an animation or whatever else you can think of. 8

For documentation on the Android API you can go to: http://developer.android.com/reference/packages.html. The Android API guides are also a good place to look for ideas and can be found at: http://developer.android.com/guide/components/index.html. Demo your application to your TA and have them fill out the lab evaluation form. You have completed your first lab and Android application! 9