Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.

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

Android User Interface
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.
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
Creating Web Page Forms
Android: Layouts David Meredith
Creating Android user interfaces using layouts 1Android user interfaces using layouts.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Android Development: Application Layout Richard S. Stansbury 2015.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Modify Android Objects Using.
PROG Mobile Java Application Development PROG Mobile Java Application Development Developing Android Apps: Components & Layout.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Mobile Programming Lecture 2 Layouts, Widgets, Toasts, and Event Handling.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Android Layouts. Layouts Define the user interface for an activity Layouts are defined in.xml files – within /res/layout folder – different layout can.
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.
Understanding Hello Android 1 CS300. Activity  Similar to a form  Base class for the visual, interactive components of your application  Android API.
Basic Android Tutorial USF’s Association for Computing Machinery.
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.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
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.
Introduction to HTML Part 3 Chapter 2. Learning Outcomes Identify how to design frames. Explain frames’ attributes. Describe the method on designing forms.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Designer Basics.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters.
Handling View Events. Open the *MainActivity.java* which is the Activity that hosts the layout in "activity_main.xml". The setContentView method inside.
Styles, Dialog Boxes, and Menus. Styles Allow creation of a common format – placed in res/values/styles.xml – file name is incidental Can be applied.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Building User Interfaces Basic Applications
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.
Using Custom Submission Questions and Questionnaires in Editorial Manager™ Created by J. Strusz (9/21/2010)
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
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 –
Graphical User Interface Concepts - Part 1 Session 08 Mata kuliah: M0874 – Programming II Tahun: 2010.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Resources. Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type anim/XML files that define tween.
Mobile Software Development for Android - I397
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
HNDIT2417 Mobile Application Development
Chap 7. Building Java Graphical User Interfaces
CIS 470 Mobile App Development
Lecture 2 b: Android Layout Basics Topics
Building User Interfaces Basic Applications
Android Developer Fundamentals V2
Android Developer Fundamentals V2
CIS 470 Mobile App Development
Building a Simple User Interface
User Interface Screen Elements
User Interface Screen Elements
CS 240 – Advanced Programming Concepts
Chapter 5 Your Second Activity.
Android Sensor Programming
Presentation transcript:

Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts

Overview  Views  Layouts  Passing data between Activities  via onActivityResult  via Application

Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views

Views  Basic Views  EditText  CheckBox  RadioButton

Graphical Editor  The graphical editor allows for drag-and-drop creation of static user- interfaces  All widgets and layouts described here are located under Form Widgets, TextFields, Layouts

EditText  EditText is simply a TextView that has been configured to be editable  Different types of pre-configured EditTexts are available in the TextFields group of the Graphical Editor  Plain Text  Password  Phone Number  etc

Using EditText  Pre-configured EditTexts handle their own validation internally  E.g. Phone numbers only accept numbers and select characters

Example  Here is an example of a Phone Number- style EditText  The keypad is set for number and phone-related characters like ‘+’

Example  In the XML file built-in validation is controlled by the android:inputType attribute <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:inputType="phone">

Extracting text  To retrieve contents of the EditText use  getText().toString()  Note: getText() itself does not return a String so you cannot just typecast the output final EditText edittext = (EditText) findViewById(R.id.edittext); String s = edittext.getText().toString();

CheckBox  CheckBoxes are used to indicate selection of a specific option  Boolean type state  Checkboxes are used for non- mutually exclusive states  You can select any, all or none of the options  The state of the CheckBox can be determined using isChecked()

Example  Alternatively, you may wait for the box to be checked by using an View.OnClickListener like with a Button final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox); checkbox.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (((CheckBox) v).isChecked()) { // check action } else { // unchecked action } } });

Alternative  If you don’t want to use an OnClickListener, you may also pullout the CheckBox from the form using findViewById(int id) and then use the isChecked() afterwards  Note: this will only be useful when you are about to finish() the current Activity final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox); if (checkbox.isChecked()) { // check action } else { // unchecked action }

RadioButton / RadioButtonGroup  RadioButtons unlike CheckBoxes are meant to be used on data where only a single selection is allowed from the list  RadioButtons are managed by a RadioButtonGroup  Controls the state of the radio buttons, if one is pressed, the group unsets the others in the group

Example  NOTE: the radio buttons must be in a radio group to function properly (only one selection)

Example  Alternatively, you may wait for the box to be checked by using an View.OnClickListener like with a Button or CheckBox final RadioButton rb = (RadioButton) findViewById(R.id.radio1); rb.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (((RadioButton) v).isChecked()) { // check action } else { // unchecked action } } });

Note  You may also programmatically control radio button state  If you need to change the state yourself, use the setChecked(boolean) or toggle() method  You may also use the RadioButtonGroup to change state  check(int id)  Id is the id of the radio button  clearCheck()  Clears the whole group

Additional View Resources  file:///C:/android-sdk- windows/docs/resources/tutorials/views /hello-formstuff.html file:///C:/android-sdk- windows/docs/resources/tutorials/views /hello-formstuff.html

Copyright© Jeffrey Jongko, Ateneo de Manila University Layouts

 Android has several built-in Layouts  LinearLayout  Either vertically or horizontally placing Views one after another  RelativeLayout  Placing views relative to the position of another view

layout_width and layout_height  These View XML attributes are usually used in reference to the container layout  Both use one of the following values  match_parent / fill_parent (depending on OS version) – fills to match width of the layout  wrap_content – sizes according to the minimum required size of the content of the View

LinearLayout  LinearLayout is a ViewGroup that displays child View elements in a linear direction, either vertically or horizontally. LinearLayoutViewGroupView  You should be careful about over-using the LinearLayout. If you begin nesting multiple LinearLayouts, you may want to consider using a RelativeLayout insteadLinearLayout RelativeLayout

layout_gravity  In addition to the basic layout_height and layout_width, Widgets also have a layout_gravity attribute to indicate which side to align the widget within the space assigned to it  Takes values such as  top  bottom  left (default)  (see Eclipse auto-complete for others)

Example  NOTE: Use of gravity varies according to widget or layout  Sometimes it is ignored <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="RIGHT" android:gravity="right"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="LEFT" android:gravity="left"/>

layout_weight  LinearLayout also supports assigning a weight to individual children.  This attribute assigns an "importance" value to a view  allows it to expand to fill any remaining space in the parent view.  Widgets with the same weight will shared the extra space equally  Child views can specify an integer weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight.  Default weight is zero.

Example  With all weights left as default  With the weight of the second textbox set to 1 with all the others set to 0(default)

RelativeLayout  RelativeLayout is a ViewGroup that displays child View elements in relative positions. The position of a View can be specified asViewGroup  relative to sibling elements (such as to the left-of or below a given element)  in positions relative to the RelativeLayout area (such as aligned to the bottom, left of center).RelativeLayout  A RelativeLayout is a very powerful utility for designing a user interface because it can eliminate nested ViewGroupsRelativeLayoutViewGroup

Example <Button android:layout_width="wrap_content“ android:layout_height="wrap_content" android:text="Cancel" />

RelativeLayout attributes  Some relative layout xml attributes:  android:layout_above - Positions the bottom edge of this view above the given anchor view ID. android:layout_above  android:layout_alignBaseline - Positions the baseline of this view on the baseline of the given anchor view ID. android:layout_alignBaseline  android:layout_alignBottom - Makes the bottom edge of this view match the bottom edge of the given anchor view ID. android:layout_alignBottom  android:layout_alignLeft - Makes the left edge of this view match the left edge of the given anchor view ID. android:layout_alignLeft  A complete list can be found in the /docs  file:///C:/android-sdk- windows/docs/reference/android/widget/RelativeLayout.LayoutPara ms.html file:///C:/android-sdk- windows/docs/reference/android/widget/RelativeLayout.LayoutPara ms.html

Nesting Layouts  Layouts can be nested within each other to form complicated groupings of widgets  This is normally required when you want to control the layouting of a group of widgets as a single entity

Additional Layout Resources  file:///C:/android-sdk- windows/docs/resources/tutorials/views /index.html file:///C:/android-sdk- windows/docs/resources/tutorials/views /index.html

Copyright© Jeffrey Jongko, Ateneo de Manila University Form Management

 When making forms/activities it is required that you remember certain things such as  If an activity may spawn one or more activities depending on the situation  How do you know which one just happened?  If data from the next activity is needed what do you do if the activity is canceled?  Either through a button or hitting the BACK button

onActivityResult()  onActivityResult(int requestCode, int resultCode, Intent data) method triggers when the just closed activity is meant to return data to the current activity  It contains all the information needed to identify  Which activity just closed  The state the activity was in when closed  The returned data itself

requestCode  When you call startActivityForResult(int requestCode, Intent intent)  requestCode is a arbitrary integer representing what the next activity is  0 could mean entering an activity to input a name  1 could mean entering an activity to input an address

resultCode  When you call setResult(int resultCode, Intent data)  resultCode is an arbitrary integer representing the exit state of the activity  0 could mean OK  1 could mean Cancel  This can be later used to determine later actions

Data Flow FORM TextView1 (Name) TextView2(PhoneNumber) BUTTON1 (Input Name) BUTTON2 (Input #) INPUT FORM TextView (Label) EditText (input field) BUTTON1 (Done) BUTTON2 (Cancel) requestCode = 0 requestCode = 1 resultCode = 0 resultCode = 1 onActivityResult(requestCode, resultCode, intent) NOTE: Ideally, you should use constants instead of hard- coded numbers to make sure your values are consistent

BACK behaviour  The pressing the BACK cause the Activity to finish()  This can be a problem if the previous activity is waiting for data  E.g. the intent return will not have anything  The onBackPressed() method can be overridden to change this default behaviour  i.e. allow adding of intent data, result info

Example public void onBackPressed() { EditText b = (EditText) findViewById(R.id.editText1); String text = b.getText().toString(); Intent data = getIntent(); data.putExtra("INPUT", text); setResult(0, data); super.onBackPressed(); }

Back-ing when expecting data  When you hit BACK on an activity that is supposed to return a result by default the result will be null  i.e. The intent received on the onActivityResult() is null