Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.

Slides:



Advertisements
Similar presentations
Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Advertisements

Programming with Android: Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
User Interface Classes.  Design Principles  Views & Layouts  Event Handling  Menus  Dialogs.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Who Am I And Why Am I Here I’m professor Stephen Fickas in CIS – you can call me Steve. I have a research group that works with mobile devices (since 1995!)
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Layout and Control in UI The user interface (UI) is the graphical interface user can see and interact with your app comprising UI controls like textbox,
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Introducing the Sudoku Example
CS5103 Software Engineering Lecture 08 Android Development II.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Mobile Programming Lecture 6
1 Mobile Computing Advanced Touching Copyright 2014 by Janson Industries Assg Part1Assg Part1 AssgPart2AssgPart2.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Presented By: Muhammad Tariq Software Engineer Android Training course.
Import import android.graphics.Bitmap; import android.widget.ImageView;
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Handling View Events. Open the *MainActivity.java* which is the Activity that hosts the layout in "activity_main.xml". The setContentView method inside.
Android App Basics Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
MOBILE COMPUTING D10K-7D02 MC04: Layouts Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
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.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Mobile Computing Lecture#12 Graphics & Animation.
BUILDING A SIMPLE USER INTERFACE. In this lesson, you create a layout in XML that includes a text field and a button. In the next lesson, your app responds.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
Http :// developer. android. com / guide / topics / fundamentals. html.
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
Lab7 – Appendix.
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
CS499 – Mobile Application Development
Adapting to Display Orientation
Android – Event Handling
Android Introduction Hello Views Part 1.
ITEC535 – Mobile Programming
Politeknik Elektronika Negeri Surabaya
Reactive Android Development
CIS 470 Mobile App Development
Android Programming Lecture 6
CIS 470 Mobile App Development
Graphics with Canvas.
Building User Interfaces Basic Applications
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Android Developer Fundamentals V2
CIS 470 Mobile App Development
Android Developer Fundamentals V2
CIS 470 Mobile App Development
Korea Software HRD Center
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

Android Form Elements

Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time pickers Auto-complete Can mostly be placed in UI using main.xml

Layouts Groups of Views Specify how they are arranged in the window Linear: arranged side-by-side Relative: with respect to other Views Table: row-by-row Tab: each Activity/View has its own window GridView: m-by-n grid ListView: scrollable list

Adding form elements to the UI Use the different Layouts and Views in main.xml Layouts can be nested Views should specify width and height – fill_parent: use up as much space as possible – wrap_content: only use as much space as needed – weight: relative size compared to other elements Specify IDs for Views that you will access in code

Nested LinearLayout Button EditText: “howMany” DrawableView (that we created): “drawableView” TextView

Modify main.xml in your FunWithDrawing project like this: <LinearLayout xmlns:android=" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="wrap_content" > 7 8 <LinearLayout 9 android:orientation="horizontal" 10 android:layout_width="fill_parent" 11 android:layout_height="fill_parent" > 12 13<TextView 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:text="Enter a number" /> 17 18<EditText 19android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:layout_weight="1" /> 22 23<Button 24android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:text="Submit!"/> <edu.upenn.cs4hs.DrawableView 30 android:layout_width="fill_parent" 31 android:layout_height="wrap_content" 32 android:layout_weight="1" /> 33 34

Handling UI Events in Forms

Handling user interaction Recall that each View has an onTouchEvent method that is automatically called by Android when the user interacts with the View In the Android View classes, Events are dispatched to registered Listeners depending on the type of action (click, key press, long click, etc.) For Buttons, you can simply use the main.xml file to specify the method used to handle clicks

Adding a Button click handler 1. Edit main.xml and so that the Button's “onClick” attribute is set to the onSubmitButtonClick method 1. Implement the onSubmitButtonClick method in your class that extends Activity 1.Be sure to use the appropriate method signature!

Add the Button's onClick attribute (line 27) in main.xml <LinearLayout xmlns:android=" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="wrap_content" > 7 8 <LinearLayout 9 android:orientation="horizontal" 10 android:layout_width="fill_parent" 11 android:layout_height="fill_parent" > 12 13<TextView 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:text="Enter a number" /> 17 18<EditText 19android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:layout_weight="1" /> 22 23<Button 24android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:text="Submit!" 27 android:onClick="onSubmitButtonClick" /> <edu.upenn.cs4hs.DrawableView 31 android:layout_width="fill_parent" 32 android:layout_height="wrap_content" 33 android:layout_weight="1" /> 34 35

Next, add this method to your FunWithDrawingActivity class 1 /* 2 * When the button is clicked, this method 3 * gets called. 4 */ 5 public void onSubmitButtonClick(View view) { 6 7 // get the EditText View by its ID 8 EditText et = (EditText)findViewById(R.id.howMany); 9 10 // get its text 11 String text = et.getText().toString(); 12 // convert to an int 13 int howMany = Integer.parseInt(text); // get the DrawableView by its ID 16 DrawableView dv = (DrawableView)findViewById(R.id.drawableView); 17 // set its count variable 18 dv.setCount(howMany); 19 // redraw the View 20 dv.invalidate(); 21 }

Now change your DrawableView class to draw random squares 1 package edu.upenn.cs4hs; 2 3 public class DrawableView extends View { 4 5 // These stay the same as before 6 public DrawableView(Context c) { 7 super(c); 8 } 9 public DrawableView(Context c, AttributeSet a) { 10 super(c, a); 11 } // add this variable to represent the number of squares 14 private int count; // this allows the count to be set 17 public void setCount(int c) { count = c; }

Rewrite this method in the DrawableView class // this version of onDraw randomly chooses a color 19 // and position for drawing the rectangles 20 protected void onDraw(Canvas canvas) { // this is the “paintbrush” 23 Paint paint = new Paint(); // loop for each rectangle to draw 26 for (int i = 0; i < count; i++) { 27 // set the color randomly 28 int whichColor = (int)(Math.random() * 4); 29 if (whichColor == 0) paint.setColor(Color.RED); 30 else if (whichColor == 1) paint.setColor(Color.GREEN); 31 else if (whichColor == 2) paint.setColor(Color.BLUE); 32 else paint.setColor(Color.YELLOW); // set the position randomly 35 int x = (int)(Math.random()*200); 36 int y = (int)(Math.random()*300); // draw Rectangle 39 canvas.drawRect(x, y, x+50, y+50, paint); 40 } } } // end of DrawableView class

Where could you go from here? Draw random sized rectangles instead of 50x50 squares Draw random shapes instead of rectangles Detect that the user has touched one of the random shapes Detect “gestures” around the shape (by using the sequence of MotionEvent objects that are passed to onTouchEvent)