SlideShare uma empresa Scribd logo
1 de 37
Mobile Computing I
Lab session 3

Thenraja Vettivelraj
Department of Computer Science
Soran University
Last session
Hello world application…
This session
Creating User Interfaces
• Fundamental Android UI Design
• Introducing Views
• Introducing Layouts
• Creating New Views
• Drawable Resources
• Resolution and Density Independence
• Creating and Using Menus
Fundamental Android UI Design
1. Views
2. View Groups
3. Activities
Architecture of Android User
Interface Components Architecture

UI Layout

UI Elements

UI Elements

Viewgroup

View

View

View

Viewgroup

View
UI
• A View is an object that draws something on the screen that the
user can interact with.
• A View is an object that you can put on your layout such as a
TextView, EditText, ListView, or ImageView. It is the basic building
block for user interface components.
• A ViewGroup is an object that holds other View (and ViewGroup)
objects in order to define the layout of the interface.
• Each view group is an invisible container that organizes child
views, while the child views may be input controls or other widgets
that draw some part of the UI.
• ViewGroup (LinearLayout) View (TextView)
Android Views
Button - A push-button that can be pressed, or clicked, by the user to perform an
action.
• TextView - This control is used to display text to the user.
• EditText - EditText is a predefined subclass of TextView that includes rich
editing capabilities.
• AutoCompleteTextView - The AutoCompleteTextView is a view that is similar
to EditText, except that it shows a list of completion suggestions automatically
while the user is typing.
• ImageButton – Absolute Layout enables you to specify the exact location of its
children.
• CheckBox - An on/off switch that can be toggled by the user. You should use
checkboxes when presenting users with a group of selectable options that are not
mutually exclusive.
• ToggleButton - An on/off button with a light indicator.
• RadioButton - The RadioButton has two states: either checked or unchecked.
• Spinner - A drop-down list that allows users to select one value from a set.
• DatePicker - The DatePicker view enables users to select a date of the day.
And others you check in the Eclipse IDE
•
Button and Events
Click button-> Event triggered->received by android os->interested one listens
android.widget.Button
android:onClick="doSomething " attribute one way to respond events
public void doSomething(View v)
implements OnClickListener
link xml and java(findViewById)
refer code in java by saying that this particular class implements the listener.
Step 1: Tell android you are interested in listening to a button clickimplements OnClickListener
Step 2: Bring xml inside java
Step 3: Tell your java button who is responding when it is clicked
Step 4: Tell what should happen when clicked
Button and Events
1.Activity implements OnClickListener

2.Separate class which implements OnClickListener
create an object in the main class for the class which handles it
3.Using interface variable(anonymous inner class)

Activities - user interacts
Services - runs in main thread, users cannot see them, even activity
off it will run, background e.g., downloading a file
Broadcast receivers- sleeps all the time e,g., battery is low
notification will be thrown
Intent- messenger
use an intent to start a new activity(e,g., going to a different page)
Method 1 - Handling Events
using OnClick xml attribute
<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:paddingBottom="@dimen/activity_vertical_m
argin"
android:paddingLeft="@dimen/activity_horizontal_ma
rgin"
android:paddingRight="@dimen/activity_horizontal_
margin"
android:paddingTop="@dimen/activity_vertical_marg
in"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:onClick="doSomething"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="73dp"
android:layout_marginTop="30dp"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:onClick="doSomething"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="67dp"
android:text="Button 2" />
</RelativeLayout>
Java file
package com.example.andon;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void doSomething(View v)
{
if(v.getId()==R.id.button1)
{
Log.d("Thens", "Button1");
Intent browserIntent = new
Intent(Intent.ACTION_VIEW, Uri.parse("http://www.googl
e.com"));
startActivity(browserIntent);
}
else if(v.getId()==R.id.button2)
{
Log.d("Thens", "Button2");
Intent browserIntent = new
Intent(Intent.ACTION_VIEW, Uri.parse("http://developer.a
ndroid.com"));
startActivity(browserIntent);
}
}
}
Screenshots of handling the
Events
•

When clicked on button 1
Method 2 - Activity implementing
OnClickListener

package com.example.bz;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements
OnClickListener {
Button b1,b2;
@Override
protected void onCreate(Bundle
savedInstanceState) {

public void onClick(View v)
{
if(v.getId()==R.id.button1)
{
Log.d("Thens", "Button1");
Intent browserIntent = new
Intent(Intent.ACTION_VIEW, Uri.parse("http:/
/www.google.com"));
startActivity(browserIntent);
}
else if(v.getId()==R.id.button2)
{
Log.d("Thens", "Button2");
}

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(this);
b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(this);
}
@Override

}
}
Method 3 - Using Inner class
package com.example.dem;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button b1;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new Thena());
}

class Thena implements
OnClickListener{
@Override
public void onClick(View v) {
Log.d("Then", "Action Listener
implemented in button1");
// TODO Auto-generated method
stub
}
}
}
Method 4 - Using Interface
Variable
package com.example.dem;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button b1;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(thenI);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
OnClickListener thenI =new OnClickListener(){
@Override
public void onClick(View v) {
Log.d("Then", "Action Listener in button1 using Interface
variable");
// TODO Auto-generated method stub
}
};
}
}
Method 5 - Anonymous Inner
Class
package com.example.dem;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button b1;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.d("Then", "Anonymous Inner class");
// TODO Auto-generated method stub
}}
);}
}
Layout
•
•
•
•
•

Linear Layout
Relative Layout
Grid Layout
Table Layout
Frame Layout
Values used
•

•

wrap_content – The component just want to display big enough to
enclose its content only.
fill_parent – The component want to display as big as its parent, and fill
in the remaining spaces.
Linear Layout
• Linear layout arranges all the children widgets in one direction like
vertical or horizontal as shown in the image.
Linear layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/
res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/to" >
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/sub" />

<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="332dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="send" />
</LinearLayout>
Linear layout xml attributes
Screenshot of Linear Layout
Relative Layout
•

•

Position of each view(e.g, Textview, Radiobutton) is decided with respect to another
view.
Relative layout arranges the children widgets relative to the parent layout or relative
to each other. Best way to understand it, look at the image.
Relative Layout.xml
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="58dp"
android:layout_marginTop="21dp"
android:layout_toLeftOf="@+id/button2"
android:text="LOGIN" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"

android:layout_below="@+id/textView1"
android:layout_marginTop="40dp"
android:text="Username" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="text" >

<requestFocus />
</EditText>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_below="@+id/editText1"
android:layout_marginTop="48dp"
android:layout_toLeftOf="@+id/editText1"
android:text="Password" />
Relative Layout.xml
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_alignRight="@+id/editText1"
android:layout_alignTop="@+id/textView3"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_marginTop="26dp"
android:layout_toRightOf="@+id/button3"
android:text="Submit" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:text="CLEAR" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:text="CANCEL" />
</RelativeLayout>
Screenshot of Relative Layout
Table Layout
•

•

Table layouts in Android works in the same way HTML table layouts work.
You can divide your layouts into rows and columns. Its very easy to
understand.
Here all child views are arranged in the form of a table. No. of rows and
columns of the table can be explicitly defined.
Table Layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/re
s/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />

<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4" />

</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

</TableRow>

</TableLayout>
Screenshot of Table Layout
Frame Layout
•

•

FrameLayout is designed to display a single item at a time. You can have multiple
elements within a FrameLayout but each element will be positioned based on the top
left of the screen. Elements that overlap will be displayed overlapping. I have created
a simple XML layout using FrameLayout that shows how this works.
Since Frame Layout is only able to display single UI element at a time or multiple UI
elements but each of them is overlapping on each others, so you can see that
Frame Layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:maxHeight="@dimen/activity_horizontal_margin"
android:text="Mobile Computing" />

</FrameLayout>
Screenshot of Frame Layout
Grid View and Grid Layout
• A GridView is a ViewGroup that displays items in twodimensional scrolling grid. The items in the grid come from
the ListAdapter associated with this view.
• This is what you'd want to use (keep using). Because a
GridView gets its data from a ListAdapter, the only data
loaded in memory will be the one displayed on screen.
GridViews, much like ListViews reuse and recycle their views
for better performance.
• Whereas a GridLayout is a layout that places its children in
a rectangular grid.
• It was introduced in API level 14, and was recently backported
in the Support Library. Its main purpose is to solve alignment
and performance problems in other layouts.
Grid Layout
• GridLayout was introduced with Android 4.0. This
layout allows you to organize a view into a Grid.
GridLayout separates its drawing area into:
rows, columns, and cells.
• You can specify how many columns you want for
define for each View in which row and column it
should be placed and how many columns and rows
it should use. If not specified GridLayout uses
defaults, e.g. one column, one row and the position
of a View depends on the order of the declaration
of the Views.
Designing a Login screen
• Will be continued next in next lab
session…

Mais conteúdo relacionado

Mais procurados

Interfacing android with embedded systems
Interfacing android with embedded systemsInterfacing android with embedded systems
Interfacing android with embedded systemsRaghav Shetty
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspectiveGunjan Kumar
 
Android chapter02-setup1-sdk
Android chapter02-setup1-sdkAndroid chapter02-setup1-sdk
Android chapter02-setup1-sdkTran Le Hoan
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from ScratchTaufan Erfiyanto
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copyDeepa Rani
 
Introduction to android coding
Introduction to android codingIntroduction to android coding
Introduction to android codingHari Krishna
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologiesjerry vasoya
 
Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017Ivo Neskovic
 
Create your First Watchkit App
Create your First Watchkit AppCreate your First Watchkit App
Create your First Watchkit AppPawan Ramteke
 
Eclipse & android setup
Eclipse & android setupEclipse & android setup
Eclipse & android setupChina Bigs
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answerskavinilavuG
 

Mais procurados (20)

Android session 1
Android session 1Android session 1
Android session 1
 
Interfacing android with embedded systems
Interfacing android with embedded systemsInterfacing android with embedded systems
Interfacing android with embedded systems
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspective
 
Android wear notes
Android wear notesAndroid wear notes
Android wear notes
 
Android session 2
Android session 2Android session 2
Android session 2
 
Android chapter02-setup1-sdk
Android chapter02-setup1-sdkAndroid chapter02-setup1-sdk
Android chapter02-setup1-sdk
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from Scratch
 
Android development module
Android development moduleAndroid development module
Android development module
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installation
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copy
 
Android tutorial1
Android tutorial1Android tutorial1
Android tutorial1
 
Android session 3
Android session 3Android session 3
Android session 3
 
Android course (lecture2)
Android course (lecture2)Android course (lecture2)
Android course (lecture2)
 
Introduction to android coding
Introduction to android codingIntroduction to android coding
Introduction to android coding
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017
 
Create your First Watchkit App
Create your First Watchkit AppCreate your First Watchkit App
Create your First Watchkit App
 
Eclipse & android setup
Eclipse & android setupEclipse & android setup
Eclipse & android setup
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answers
 

Semelhante a Android App development III

ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docPalakjaiswal43
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & IntentsLope Emano
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intentsVitali Pekelis
 
Get an Android tutorial for beginners
Get an Android tutorial for beginnersGet an Android tutorial for beginners
Get an Android tutorial for beginnersJavaTpoint.Com
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Androidma-polimi
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentAly Abdelkareem
 
Android Homescreen Widgets Demystified
Android Homescreen Widgets DemystifiedAndroid Homescreen Widgets Demystified
Android Homescreen Widgets DemystifiedPearl Chen
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application DevelopmentMuhammad Sajid
 

Semelhante a Android App development III (20)

Activity & Shared Preference
Activity & Shared PreferenceActivity & Shared Preference
Activity & Shared Preference
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.doc
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
 
Lecture #3 activities and intents
Lecture #3  activities and intentsLecture #3  activities and intents
Lecture #3 activities and intents
 
Android user interface design-chapter13
Android user interface design-chapter13Android user interface design-chapter13
Android user interface design-chapter13
 
Get an Android tutorial for beginners
Get an Android tutorial for beginnersGet an Android tutorial for beginners
Get an Android tutorial for beginners
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
UIAutomator
UIAutomatorUIAutomator
UIAutomator
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Notes Unit3.pptx
Notes Unit3.pptxNotes Unit3.pptx
Notes Unit3.pptx
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android Homescreen Widgets Demystified
Android Homescreen Widgets DemystifiedAndroid Homescreen Widgets Demystified
Android Homescreen Widgets Demystified
 
Notes Unit4.pptx
Notes Unit4.pptxNotes Unit4.pptx
Notes Unit4.pptx
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application Development
 

Último

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Último (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Android App development III

  • 1. Mobile Computing I Lab session 3 Thenraja Vettivelraj Department of Computer Science Soran University
  • 2. Last session Hello world application…
  • 3. This session Creating User Interfaces • Fundamental Android UI Design • Introducing Views • Introducing Layouts • Creating New Views • Drawable Resources • Resolution and Density Independence • Creating and Using Menus
  • 4. Fundamental Android UI Design 1. Views 2. View Groups 3. Activities
  • 5. Architecture of Android User Interface Components Architecture UI Layout UI Elements UI Elements Viewgroup View View View Viewgroup View
  • 6. UI • A View is an object that draws something on the screen that the user can interact with. • A View is an object that you can put on your layout such as a TextView, EditText, ListView, or ImageView. It is the basic building block for user interface components. • A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface. • Each view group is an invisible container that organizes child views, while the child views may be input controls or other widgets that draw some part of the UI. • ViewGroup (LinearLayout) View (TextView)
  • 7. Android Views Button - A push-button that can be pressed, or clicked, by the user to perform an action. • TextView - This control is used to display text to the user. • EditText - EditText is a predefined subclass of TextView that includes rich editing capabilities. • AutoCompleteTextView - The AutoCompleteTextView is a view that is similar to EditText, except that it shows a list of completion suggestions automatically while the user is typing. • ImageButton – Absolute Layout enables you to specify the exact location of its children. • CheckBox - An on/off switch that can be toggled by the user. You should use checkboxes when presenting users with a group of selectable options that are not mutually exclusive. • ToggleButton - An on/off button with a light indicator. • RadioButton - The RadioButton has two states: either checked or unchecked. • Spinner - A drop-down list that allows users to select one value from a set. • DatePicker - The DatePicker view enables users to select a date of the day. And others you check in the Eclipse IDE •
  • 8. Button and Events Click button-> Event triggered->received by android os->interested one listens android.widget.Button android:onClick="doSomething " attribute one way to respond events public void doSomething(View v) implements OnClickListener link xml and java(findViewById) refer code in java by saying that this particular class implements the listener. Step 1: Tell android you are interested in listening to a button clickimplements OnClickListener Step 2: Bring xml inside java Step 3: Tell your java button who is responding when it is clicked Step 4: Tell what should happen when clicked
  • 9. Button and Events 1.Activity implements OnClickListener 2.Separate class which implements OnClickListener create an object in the main class for the class which handles it 3.Using interface variable(anonymous inner class) Activities - user interacts Services - runs in main thread, users cannot see them, even activity off it will run, background e.g., downloading a file Broadcast receivers- sleeps all the time e,g., battery is low notification will be thrown Intent- messenger use an intent to start a new activity(e,g., going to a different page)
  • 10. Method 1 - Handling Events using OnClick xml attribute <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:paddingBottom="@dimen/activity_vertical_m argin" android:paddingLeft="@dimen/activity_horizontal_ma rgin" android:paddingRight="@dimen/activity_horizontal_ margin" android:paddingTop="@dimen/activity_vertical_marg in" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:onClick="doSomething" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="73dp" android:layout_marginTop="30dp" android:text="Button 1" /> <Button android:id="@+id/button2" android:onClick="doSomething" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/button1" android:layout_below="@+id/button1" android:layout_marginTop="67dp" android:text="Button 2" /> </RelativeLayout>
  • 11. Java file package com.example.andon; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void doSomething(View v) { if(v.getId()==R.id.button1) { Log.d("Thens", "Button1"); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.googl e.com")); startActivity(browserIntent); } else if(v.getId()==R.id.button2) { Log.d("Thens", "Button2"); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://developer.a ndroid.com")); startActivity(browserIntent); } } }
  • 12. Screenshots of handling the Events • When clicked on button 1
  • 13. Method 2 - Activity implementing OnClickListener package com.example.bz; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity implements OnClickListener { Button b1,b2; @Override protected void onCreate(Bundle savedInstanceState) { public void onClick(View v) { if(v.getId()==R.id.button1) { Log.d("Thens", "Button1"); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /www.google.com")); startActivity(browserIntent); } else if(v.getId()==R.id.button2) { Log.d("Thens", "Button2"); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.button1); b1.setOnClickListener(this); b2=(Button)findViewById(R.id.button2); b2.setOnClickListener(this); } @Override } }
  • 14. Method 3 - Using Inner class package com.example.dem; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.button1); b1.setOnClickListener(new Thena()); } class Thena implements OnClickListener{ @Override public void onClick(View v) { Log.d("Then", "Action Listener implemented in button1"); // TODO Auto-generated method stub } } }
  • 15. Method 4 - Using Interface Variable package com.example.dem; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.button1); b1.setOnClickListener(thenI); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } OnClickListener thenI =new OnClickListener(){ @Override public void onClick(View v) { Log.d("Then", "Action Listener in button1 using Interface variable"); // TODO Auto-generated method stub } }; } }
  • 16. Method 5 - Anonymous Inner Class package com.example.dem; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.button1); b1.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { Log.d("Then", "Anonymous Inner class"); // TODO Auto-generated method stub }} );} }
  • 18. Values used • • wrap_content – The component just want to display big enough to enclose its content only. fill_parent – The component want to display as big as its parent, and fill in the remaining spaces.
  • 19. Linear Layout • Linear layout arranges all the children widgets in one direction like vertical or horizontal as shown in the image.
  • 20. Linear layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/ res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="@string/to" > </EditText> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="@string/sub" /> <EditText android:id="@+id/editText3" android:layout_width="match_parent" android:layout_height="332dp" android:ems="10" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="send" /> </LinearLayout>
  • 21. Linear layout xml attributes
  • 23. Relative Layout • • Position of each view(e.g, Textview, Radiobutton) is decided with respect to another view. Relative layout arranges the children widgets relative to the parent layout or relative to each other. Best way to understand it, look at the image.
  • 24. Relative Layout.xml <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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="58dp" android:layout_marginTop="21dp" android:layout_toLeftOf="@+id/button2" android:text="LOGIN" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView3" android:layout_below="@+id/textView1" android:layout_marginTop="40dp" android:text="Username" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView2" android:layout_alignBottom="@+id/textView2" android:layout_alignParentRight="true" android:ems="10" android:inputType="text" > <requestFocus /> </EditText> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button3" android:layout_below="@+id/editText1" android:layout_marginTop="48dp" android:layout_toLeftOf="@+id/editText1" android:text="Password" />
  • 25. Relative Layout.xml <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_alignRight="@+id/editText1" android:layout_alignTop="@+id/textView3" android:ems="10" android:inputType="textPassword" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText2" android:layout_marginTop="26dp" android:layout_toRightOf="@+id/button3" android:text="Submit" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_toRightOf="@+id/button1" android:text="CLEAR" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/button1" android:text="CANCEL" /> </RelativeLayout>
  • 26.
  • 28. Table Layout • • Table layouts in Android works in the same way HTML table layouts work. You can divide your layouts into rows and columns. Its very easy to understand. Here all child views are arranged in the form of a table. No. of rows and columns of the table can be explicitly defined.
  • 29. Table Layout.xml <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/re s/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" /> <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 3" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 4" /> </TableRow> <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content" > </TableRow> </TableLayout>
  • 31. Frame Layout • • FrameLayout is designed to display a single item at a time. You can have multiple elements within a FrameLayout but each element will be positioned based on the top left of the screen. Elements that overlap will be displayed overlapping. I have created a simple XML layout using FrameLayout that shows how this works. Since Frame Layout is only able to display single UI element at a time or multiple UI elements but each of them is overlapping on each others, so you can see that
  • 32. Frame Layout.xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:maxHeight="@dimen/activity_horizontal_margin" android:text="Mobile Computing" /> </FrameLayout>
  • 34. Grid View and Grid Layout • A GridView is a ViewGroup that displays items in twodimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view. • This is what you'd want to use (keep using). Because a GridView gets its data from a ListAdapter, the only data loaded in memory will be the one displayed on screen. GridViews, much like ListViews reuse and recycle their views for better performance. • Whereas a GridLayout is a layout that places its children in a rectangular grid. • It was introduced in API level 14, and was recently backported in the Support Library. Its main purpose is to solve alignment and performance problems in other layouts.
  • 35. Grid Layout • GridLayout was introduced with Android 4.0. This layout allows you to organize a view into a Grid. GridLayout separates its drawing area into: rows, columns, and cells. • You can specify how many columns you want for define for each View in which row and column it should be placed and how many columns and rows it should use. If not specified GridLayout uses defaults, e.g. one column, one row and the position of a View depends on the order of the declaration of the Views.
  • 37. • Will be continued next in next lab session…