SlideShare a Scribd company logo
1 of 46
Build 
User 
Interface 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
張明禾 
• C 
• Android 
App 
• NodeJS 
• Sencha 
Touch 
• Unity 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Tips 
• Debug 
– 
LogCat 
– Log.d/Log.e/Log.i/Log.v/Log.w 
– Log.d("TAG", 
"Something’s 
wrong!!!"); 
• Useful 
Eclipse 
shortcuts 
for 
Windows 
Ac$on 
Shortcut 
Auto 
Complete(Content 
Assist) 
Alt 
+ 
/ 
Auto 
Imports 
Ctrl 
+ 
ShiW 
+ 
O 
Refactoring 
Alt 
+ 
ShiW 
+ 
R 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Build 
by 
drag 
& 
drop 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Build 
by 
programming 
<Buon 
android:id="@+id/myBuon" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
/> 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
View 
& 
ViewGroup(Layout) 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
• LinearLayout 
• RelacveLayout 
• ListView 
• GridView 
• … 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
View 
• Buon/ImageBuon 
• TextView 
• EditText 
• ImageView 
• CheckBox 
• … 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
1st 
implementacon 
• Build 
a 
UI 
like 
• 都教授:textSize="20sp" 
• File 
-­‐> 
New 
-­‐> 
Android 
XML 
File 
2014/9/9– 
File: 
list_item.xmCoply 
right 
© 
2014 
MingHo 
Chang
Standard 
UI 
Layout 
• Accon 
Bar 
• Dialogs 
• Status 
Nocficacons 
• Toasts 
• … 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Ac$vity 
Lifecycle 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
2nd 
implementacon 
• Print 
every 
lifecycle 
method’s 
name 
in 
LogCat 
while 
the 
it 
is 
triggered. 
• Example: 
@Override 
public 
void 
onStart() 
{ 
super.onStart(); 
Log.i("Implementacon", 
"onStart"); 
} 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
• layout.xml 
<ListView 
android:id="@+id/myListView" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
/> 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
• Default 
list 
item 
layout 
– android.R.layout.simple_list_item_1 
– android.R.layout.simple_list_item_2 
– android.R.layout.simple_list_item_single_choice 
– android.R.layout.simple_list_item_mulcple_choice 
– android.R.layout.simple_list_item_checked 
• hp://developer.android.com/reference/ 
android/R.layout.html 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
• Set 
list 
content 
by 
adapter 
– ArrayAdapter 
– SimpleAdapter 
– BaseAdapter 
– SimpleCursorAdapter 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
• ArrayAdapter 
-­‐ 
onCreate 
String[] 
values 
= 
new 
String[]{ 
"item1", 
"item2", 
"item3", 
"item4", 
"item5" 
}; 
ListView 
list 
= 
(ListView) 
findViewById(R.id.myListView); 
ArrayAdapter 
listAdapter 
= 
new 
ArrayAdapter<String> 
(this, 
android.R.layout.simple_list_item_1, 
values); 
list.setAdapter(listAdapter); 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
3rd 
implementacon 
• Create 
a 
list 
with 
10 
classmates’ 
names. 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
• Customize 
list 
item 
layout. 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
• Classmate.java 
public 
class 
Classmate 
{ 
public 
String 
name; 
public 
String 
descripcon; 
public 
int 
imageRes; 
public 
Classmate(String 
n, 
String 
des, 
int 
res) 
{ 
name 
= 
n; 
descripcon 
= 
des; 
imageRes 
= 
res; 
} 
} 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
• BaseAdapter 
– 
CustomAdapter.java 
public 
class 
CustomAdapter 
extends 
BaseAdapter 
{ 
private 
List<Classmate> 
mList; 
private 
LayoutInflater 
mInflater; 
public 
CustomAdapter(Context 
context, 
List<Classmate> 
list) 
mList 
= 
list; 
mInflater 
= 
LayoutInflater.from(context); 
} 
} 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
@Override 
public 
int 
getCount() 
{ 
return 
mList.size(); 
} 
@Override 
public 
Classmate 
getItem(int 
posicon) 
{ 
return 
mList.get(posicon); 
} 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
@Override 
public 
long 
getItemId(int 
posicon) 
{ 
return 
0; 
} 
private 
class 
ViewHolder 
{ 
ImageView 
imgView; 
TextView 
txtTitle; 
TextView 
txtDesc; 
} 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
@Override 
public 
View 
getView(int 
posicon, 
View 
convertView, 
ViewGroup 
parent) 
{ 
ViewHolder 
holder 
= 
null; 
if 
(convertView 
== 
null) 
{ 
convertView 
= 
mInflater.inflate(R.layout.list_item, 
null); 
holder 
= 
new 
ViewHolder(); 
holder.txtDesc 
= 
(TextView) 
convertView.findViewById(R.id.desc); 
holder.txtTitle 
= 
(TextView) 
convertView.findViewById(R.id.ctle); 
holder.imgView 
= 
(ImageView) 
convertView.findViewById(R.id.icon); 
convertView.setTag(holder); 
} 
else 
{ 
holder 
= 
(ViewHolder) 
convertView.getTag(); 
} 
Classmate 
c 
= 
getItem(posicon); 
holder.txtTitle.setText(c.name); 
// 
TODO 
return 
convertView; 
} 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
• MainAccvity.java 
public 
class 
MainAccvity 
extends 
Accvity 
{ 
private 
List<Classmate> 
mClassmates; 
… 
} 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView(Customize) 
• MainAccvity.java 
– 
onCreate 
mClassmates 
= 
new 
ArrayList(); 
mClassmates 
.add(new 
Classmate("Mary", 
"A 
girl", 
R.drawable.mary)); 
mClassmates 
.add(new 
Classmate("Tom", 
"A 
boy", 
R.drawable.tom)); 
ListView 
list 
= 
(ListView) 
findViewById(R.id.myListView); 
CustomAdapter 
listAdapter 
= 
new 
CustomAdapter(this, 
mClassmates 
); 
list.setAdapter(listAdapter); 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
4th 
implementacon 
• Build 
the 
list 
above 
with 
pictures, 
classmates’ 
names 
and 
descripcons. 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Event 
Listeners 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Event 
Listeners 
• Views 
– onClick 
– onLongClick 
– onTouch 
• ListView 
– onItemClick 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
• OnItemClickListener 
private 
OnItemClickListener 
mItemClickListener 
= 
new 
OnItemClickListener() 
{ 
@Override 
public 
void 
onItemClick(AdapterView<?> 
adapter, 
View 
view, 
int 
posicon, 
long 
id) 
{ 
// 
TODO 
} 
}; 
list.setOnItemClickListener(mItemClickListener); 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Drawable 
• Place 
images 
in 
res/drawable/ 
. 
• Get 
images 
by 
R.drawable.image_name 
when 
programming. 
• Ex: 
<ImageView 
android:src="@drawable/image_name" 
/> 
ImageView 
image; 
image.setImageResource(R.drawable.image_name); 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
5th 
implementacon 
• Toast 
a 
message 
while 
clicking 
any 
list 
item. 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
The 
End 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
LinearLayout 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
LinearLayout 
<LinearLayout 
android:id="@+id/myLinearLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientacon="verccal" 
> 
…views… 
</LinearLayout> 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
LinearLayout 
<LinearLayout 
… 
android:orientacon="verccal" 
> 
<buon 
… 
android:layout_height="0dp" 
android:layout_weight="2" 
/> 
<buon 
… 
android:layout_height="0dp" 
android:layout_weight="1" 
/> 
</LinearLayout> 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
LinearLayout 
<LinearLayout 
… 
android:orientacon="horizontal" 
> 
<buon 
… 
android:layout_width="0dp" 
android:layout_weight="2" 
/> 
<buon 
… 
android:layout_width="0dp" 
android:layout_weight="1" 
/> 
</LinearLayout> 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
RelacveLayout 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
RelacveLayout 
• android:layout_alignParentTop="true" 
• android:layout_centerVerccal="true" 
• android:layout_below="@id/myBuon" 
• android:layout_toRightOf="@id/myBuon" 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
ListView 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
ViewGroup 
-­‐ 
GridView 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Standard 
UI 
Layout 
– 
Accon 
Bar 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Standard 
UI 
Layout 
-­‐ 
Dialog 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Standard 
UI 
Layout 
-­‐ 
Nocficacon 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang
Standard 
UI 
Layout 
-­‐ 
Toast 
Toast.makeText(getApplicaconContext(), 
"msg", 
Toast.LENGTH_SHORT).show(); 
2014/9/9 
Copyright 
© 
2014 
MingHo 
Chang

More Related Content

Similar to Android - Build User Interface

Android - Intents and Broadcast Receivers
Android - Intents and Broadcast ReceiversAndroid - Intents and Broadcast Receivers
Android - Intents and Broadcast ReceiversMingHo Chang
 
Embracing the Lollipop
Embracing the LollipopEmbracing the Lollipop
Embracing the LollipopSonja Kesic
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDMaterial Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDJordan Open Source Association
 
Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Oliver Wahlen
 
Android Development project
Android Development projectAndroid Development project
Android Development projectMinhaj Kazi
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android AppsGil Irizarry
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material DesignYasin Yildirim
 
ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013Mathias Seguy
 
A resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleA resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleAkihito Koriyama
 
Building interactive app
Building interactive appBuilding interactive app
Building interactive appOmar Albelbaisy
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development PracticesRoy Clarkson
 
Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...
Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...
Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...Edureka!
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectJoemarie Amparo
 
Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101Fernando Gallego
 

Similar to Android - Build User Interface (20)

Android - Intents and Broadcast Receivers
Android - Intents and Broadcast ReceiversAndroid - Intents and Broadcast Receivers
Android - Intents and Broadcast Receivers
 
Embracing the Lollipop
Embracing the LollipopEmbracing the Lollipop
Embracing the Lollipop
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDMaterial Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
 
Android Materials Design
Android Materials Design Android Materials Design
Android Materials Design
 
Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4
 
Android Development project
Android Development projectAndroid Development project
Android Development project
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material Design
 
Geekcamp Android
Geekcamp AndroidGeekcamp Android
Geekcamp Android
 
ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013ProTips DroidCon Paris 2013
ProTips DroidCon Paris 2013
 
A resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangleA resource oriented framework using the DI/AOP/REST triangle
A resource oriented framework using the DI/AOP/REST triangle
 
Compose In Practice
Compose In PracticeCompose In Practice
Compose In Practice
 
Building interactive app
Building interactive appBuilding interactive app
Building interactive app
 
Android programming basics
Android programming basicsAndroid programming basics
Android programming basics
 
Native Android Development Practices
Native Android Development PracticesNative Android Development Practices
Native Android Development Practices
 
Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...
Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...
Angular 4 Components | Angular 4 Tutorial For Beginners | Learn Angular 4 | E...
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample Project
 
Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101Fernando F. Gallego - Efficient Android Resources 101
Fernando F. Gallego - Efficient Android Resources 101
 

Recently uploaded

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

Android - Build User Interface

  • 1. Build User Interface 2014/9/9 Copyright © 2014 MingHo Chang
  • 2. 張明禾 • C • Android App • NodeJS • Sencha Touch • Unity 2014/9/9 Copyright © 2014 MingHo Chang
  • 3. Tips • Debug – LogCat – Log.d/Log.e/Log.i/Log.v/Log.w – Log.d("TAG", "Something’s wrong!!!"); • Useful Eclipse shortcuts for Windows Ac$on Shortcut Auto Complete(Content Assist) Alt + / Auto Imports Ctrl + ShiW + O Refactoring Alt + ShiW + R 2014/9/9 Copyright © 2014 MingHo Chang
  • 4. Build by drag & drop 2014/9/9 Copyright © 2014 MingHo Chang
  • 5. Build by programming <Buon android:id="@+id/myBuon" android:layout_width="match_parent" android:layout_height="match_parent" /> 2014/9/9 Copyright © 2014 MingHo Chang
  • 6. View & ViewGroup(Layout) 2014/9/9 Copyright © 2014 MingHo Chang
  • 7. ViewGroup • LinearLayout • RelacveLayout • ListView • GridView • … 2014/9/9 Copyright © 2014 MingHo Chang
  • 8. View • Buon/ImageBuon • TextView • EditText • ImageView • CheckBox • … 2014/9/9 Copyright © 2014 MingHo Chang
  • 9. 1st implementacon • Build a UI like • 都教授:textSize="20sp" • File -­‐> New -­‐> Android XML File 2014/9/9– File: list_item.xmCoply right © 2014 MingHo Chang
  • 10. Standard UI Layout • Accon Bar • Dialogs • Status Nocficacons • Toasts • … 2014/9/9 Copyright © 2014 MingHo Chang
  • 11. Ac$vity Lifecycle 2014/9/9 Copyright © 2014 MingHo Chang
  • 12. 2nd implementacon • Print every lifecycle method’s name in LogCat while the it is triggered. • Example: @Override public void onStart() { super.onStart(); Log.i("Implementacon", "onStart"); } 2014/9/9 Copyright © 2014 MingHo Chang
  • 13. ViewGroup -­‐ ListView 2014/9/9 Copyright © 2014 MingHo Chang
  • 14. ViewGroup -­‐ ListView • layout.xml <ListView android:id="@+id/myListView" android:layout_width="match_parent" android:layout_height="match_parent" /> 2014/9/9 Copyright © 2014 MingHo Chang
  • 15. ViewGroup -­‐ ListView • Default list item layout – android.R.layout.simple_list_item_1 – android.R.layout.simple_list_item_2 – android.R.layout.simple_list_item_single_choice – android.R.layout.simple_list_item_mulcple_choice – android.R.layout.simple_list_item_checked • hp://developer.android.com/reference/ android/R.layout.html 2014/9/9 Copyright © 2014 MingHo Chang
  • 16. ViewGroup -­‐ ListView 2014/9/9 Copyright © 2014 MingHo Chang
  • 17. ViewGroup -­‐ ListView • Set list content by adapter – ArrayAdapter – SimpleAdapter – BaseAdapter – SimpleCursorAdapter 2014/9/9 Copyright © 2014 MingHo Chang
  • 18. ViewGroup -­‐ ListView • ArrayAdapter -­‐ onCreate String[] values = new String[]{ "item1", "item2", "item3", "item4", "item5" }; ListView list = (ListView) findViewById(R.id.myListView); ArrayAdapter listAdapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_1, values); list.setAdapter(listAdapter); 2014/9/9 Copyright © 2014 MingHo Chang
  • 19. 3rd implementacon • Create a list with 10 classmates’ names. 2014/9/9 Copyright © 2014 MingHo Chang
  • 20. ViewGroup -­‐ ListView(Customize) • Customize list item layout. 2014/9/9 Copyright © 2014 MingHo Chang
  • 21. ViewGroup -­‐ ListView(Customize) • Classmate.java public class Classmate { public String name; public String descripcon; public int imageRes; public Classmate(String n, String des, int res) { name = n; descripcon = des; imageRes = res; } } 2014/9/9 Copyright © 2014 MingHo Chang
  • 22. ViewGroup -­‐ ListView(Customize) • BaseAdapter – CustomAdapter.java public class CustomAdapter extends BaseAdapter { private List<Classmate> mList; private LayoutInflater mInflater; public CustomAdapter(Context context, List<Classmate> list) mList = list; mInflater = LayoutInflater.from(context); } } 2014/9/9 Copyright © 2014 MingHo Chang
  • 23. ViewGroup -­‐ ListView(Customize) @Override public int getCount() { return mList.size(); } @Override public Classmate getItem(int posicon) { return mList.get(posicon); } 2014/9/9 Copyright © 2014 MingHo Chang
  • 24. ViewGroup -­‐ ListView(Customize) @Override public long getItemId(int posicon) { return 0; } private class ViewHolder { ImageView imgView; TextView txtTitle; TextView txtDesc; } 2014/9/9 Copyright © 2014 MingHo Chang
  • 25. ViewGroup -­‐ ListView(Customize) @Override public View getView(int posicon, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.list_item, null); holder = new ViewHolder(); holder.txtDesc = (TextView) convertView.findViewById(R.id.desc); holder.txtTitle = (TextView) convertView.findViewById(R.id.ctle); holder.imgView = (ImageView) convertView.findViewById(R.id.icon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } Classmate c = getItem(posicon); holder.txtTitle.setText(c.name); // TODO return convertView; } 2014/9/9 Copyright © 2014 MingHo Chang
  • 26. ViewGroup -­‐ ListView(Customize) • MainAccvity.java public class MainAccvity extends Accvity { private List<Classmate> mClassmates; … } 2014/9/9 Copyright © 2014 MingHo Chang
  • 27. ViewGroup -­‐ ListView(Customize) • MainAccvity.java – onCreate mClassmates = new ArrayList(); mClassmates .add(new Classmate("Mary", "A girl", R.drawable.mary)); mClassmates .add(new Classmate("Tom", "A boy", R.drawable.tom)); ListView list = (ListView) findViewById(R.id.myListView); CustomAdapter listAdapter = new CustomAdapter(this, mClassmates ); list.setAdapter(listAdapter); 2014/9/9 Copyright © 2014 MingHo Chang
  • 28. 4th implementacon • Build the list above with pictures, classmates’ names and descripcons. 2014/9/9 Copyright © 2014 MingHo Chang
  • 29. Event Listeners 2014/9/9 Copyright © 2014 MingHo Chang
  • 30. Event Listeners • Views – onClick – onLongClick – onTouch • ListView – onItemClick 2014/9/9 Copyright © 2014 MingHo Chang
  • 31. ViewGroup -­‐ ListView • OnItemClickListener private OnItemClickListener mItemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int posicon, long id) { // TODO } }; list.setOnItemClickListener(mItemClickListener); 2014/9/9 Copyright © 2014 MingHo Chang
  • 32. Drawable • Place images in res/drawable/ . • Get images by R.drawable.image_name when programming. • Ex: <ImageView android:src="@drawable/image_name" /> ImageView image; image.setImageResource(R.drawable.image_name); 2014/9/9 Copyright © 2014 MingHo Chang
  • 33. 5th implementacon • Toast a message while clicking any list item. 2014/9/9 Copyright © 2014 MingHo Chang
  • 34. The End 2014/9/9 Copyright © 2014 MingHo Chang
  • 35. ViewGroup -­‐ LinearLayout 2014/9/9 Copyright © 2014 MingHo Chang
  • 36. ViewGroup -­‐ LinearLayout <LinearLayout android:id="@+id/myLinearLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientacon="verccal" > …views… </LinearLayout> 2014/9/9 Copyright © 2014 MingHo Chang
  • 37. ViewGroup -­‐ LinearLayout <LinearLayout … android:orientacon="verccal" > <buon … android:layout_height="0dp" android:layout_weight="2" /> <buon … android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout> 2014/9/9 Copyright © 2014 MingHo Chang
  • 38. ViewGroup -­‐ LinearLayout <LinearLayout … android:orientacon="horizontal" > <buon … android:layout_width="0dp" android:layout_weight="2" /> <buon … android:layout_width="0dp" android:layout_weight="1" /> </LinearLayout> 2014/9/9 Copyright © 2014 MingHo Chang
  • 39. ViewGroup -­‐ RelacveLayout 2014/9/9 Copyright © 2014 MingHo Chang
  • 40. ViewGroup -­‐ RelacveLayout • android:layout_alignParentTop="true" • android:layout_centerVerccal="true" • android:layout_below="@id/myBuon" • android:layout_toRightOf="@id/myBuon" 2014/9/9 Copyright © 2014 MingHo Chang
  • 41. ViewGroup -­‐ ListView 2014/9/9 Copyright © 2014 MingHo Chang
  • 42. ViewGroup -­‐ GridView 2014/9/9 Copyright © 2014 MingHo Chang
  • 43. Standard UI Layout – Accon Bar 2014/9/9 Copyright © 2014 MingHo Chang
  • 44. Standard UI Layout -­‐ Dialog 2014/9/9 Copyright © 2014 MingHo Chang
  • 45. Standard UI Layout -­‐ Nocficacon 2014/9/9 Copyright © 2014 MingHo Chang
  • 46. Standard UI Layout -­‐ Toast Toast.makeText(getApplicaconContext(), "msg", Toast.LENGTH_SHORT).show(); 2014/9/9 Copyright © 2014 MingHo Chang