SlideShare a Scribd company logo
1 of 81
Creare app native su
iOS, Android, Mac &
Windows in C#
Introduzione a Xamarin.Android
Gli speaker di oggi
Guido Magrin
Xamarin & Microsoft Student Partner
Xamarin Certified Developer
@GuidoMagrin
Dove trovo le slide?
http://www.slideshare.net/guidomagrin
Gli Xamarin Student Partner
https://www.facebook.com/XSAMilano
Oggi parleremo di…
Xamarin.Android
Chi ha già
sentito parlare di
Xamarin.Android?
Xamarin + Xamarin.Forms
Approccio offerto da Xamarin.Forms:
Codice UI condiviso, controlli nativi
Approccio tradizionale di Xamarin
Shared UI Code
.NET Android APIs | 100% coverage
Qualsiasi cosa si possa fare in
Java può essere fatta in C#
con Xamarin in Visual Studio
Xamarin Studio
PC o Mac
Plugin Visual Studio
VS 2010 e superiore
Ambienti di Sviluppo
Integrazione in Visual Studio
Una soluzione sola per:
• iOS
• Android
• Windows Phone
• Windows Store
Tutti i plugin e le funzioni
di Visual Studio:
• ReSharper
• Team Foundation Server
Integrazione in Visual Studio
Debugging su:
• Emulatori
• Dispositivi
Integrati nella toolbar:
• Stato
• Logs
• Lista di dispositivi
Xamarin Studio
• Ottimizzato per lo sviluppo
cross-platform
• Accedi alle API native con
l’autocompletamento
• Designer per Android e iOS
• Debugging avanzato su
emulatore o dispositivo
Designer per Xamarin Android
• Il migliore designer per Android
• Disponibile per
• Xamarin Studio
• Visual Studio
• Crea facilmente l’interfaccia
utente tramite drag & drop
• Affronta facilmente il problema
del rescaling e della
frammentazione di Android.
• Layout salvati in file XML
Android standard
Cosa impareremo oggi?
• The package
• Activities
• Liste
The package
The package
The build process bundles the app into a single file with .apk
extension.
It’s the package that needs to be uploaded in the Google Store to
publish the app.
Permissions
The manifest file controls which
features of the platform the app can
use.
Images and screen density
• Android runs on many devices with
different screens and resolutions
• You supply the images in different sizes
with the same name
• You distinguish them applying a naming
convention to the folder where the image
is stored
Images and screen density
• Every application should have an icon and a
label
• It’s set in the manifest file
Icons and label
• Also activities can have their own icon and
label
• They are displayed in the navigation bar
• They are defined in the Activity attribute
[Activity(Label = "AndroidFundamentals", MainLauncher = true,
Icon = "@drawable/icon")]
public class MainActivity : Activity
{
...
}
API levels
• Every Android version is identified by:
– Version number (4.4, 5.1, etc.)
– Nickname (Kit Kat, Lollipop, etc.)
– API Level (19, 22, etc.)
• Every device supports a specific API level
• It’s helpful to understand if an app can run on a specific
device
API levels
• In the properties of the project you can define:
– Target API: the API level used to build the package
– Minimum API: the minimum set of supported API level
– Target Android version: API level that the app expects to use
• If API Level < Minimum API the app won’t be installed
API Level Check
• If API Level < Target API some APIs mightn’t be available
• You can detect, in code, the current API Level:
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
//use APIs that are available in Lollipop
}
else
{
//fallback to old APIs
}
Resources
• Resources can be managed using naming conventions
applied to the folder
• Examples:
– resources/drawable-it: it contains the images used on an Italian
device
– layout-land: it contains the layouts to use in landscape mode
• The Build Action must be set to AndroidResource
Resources
• Layout: interfaces
• Drawable: images
• Values: generic strings (localization)
• Color: XML files that define colors
Package
DEMO
La prima app
Xamarin.Forms
Domanda 1
Un’applicazione Android funziona senza vincoli particolari su qualsiasi
telefono sul quale sia installato Android:
a) Vero
b) Falso
Domanda 1
Un’applicazione Android funziona senza vincoli particolari su qualsiasi
telefono sul quale sia installato Android:
a) Vero
b) Falso
Domanda 2
Come si chiama il file tramite il quale posso modificare le impostazioni
di un package Android?
a) Paper
b) Resources
c) Manifest
d) Document
Domanda 2
Come si chiama il file tramite il quale posso modificare le impostazioni
di un package Android?
a) Paper
b) Resources
c) Manifest
d) Document
Domanda 3
Quali sono i tipi di Resources disponibili in un’app Android?
a) Layout, Images, Values, Brushes
b) Layout, Drawables, Values, Color
c) Disposition, Drawables, Enumerables, Color
d) UIDefine, Images, Enumerables, Brushes
Domanda 3
Quali sono i tipi di Resources disponibili in un’app Android?
a) Layout, Images, Values, Brushes
b) Layout, Drawables, Values, Color
c) Disposition, Drawables, Enumerables, Color
d) UIDefine, Images, Enumerables, Brushes
Activities
Activities
• An activity is a page that shows some content to the user.
• An application is usually composed by multiple activities.
Activities
• In Xamarin, an Activity is composed by:
– A XML file, that describes the layout (optional, it can be done also by
code)
– A code behind class, that manages the interactions with the UI
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout ...>
<TextView ... />
<EditText ... />
<Button ... />
</LinearLayout>
public class MainActivity : Activity
{
...
}
UI defined with XML C# class that inherits
from Activity and it’s
decorated with the
The Main Activity
It’s the activity that is automatically launched when the user
starts an app
The MainLauncher property
of the Activity attribute is
used to define the main activity
[Activity(MainLauncher = true]
public class MainActivity : Activity
{
...
}
Access to controls
To gain access to a control in code you need to assign an ID
Assign an ID in the XML <TextView android:id="@+id/PhoneNumber" />
// aapt resource value: 0x7f050000
public const int PhoneNumber = 2131034112;
TextView phoneNumberView =
this.FindViewById<TextView>
(Resource.Id.PhoneNumber);
The build process
generates a resource
You use the id to
access to the control
Dialogs
The AlertDialog class is used to display modal messages
var dialog = new AlertDialog.Builder(this);
dialog.SetTitle("Title");
dialog.SetMessage("Message Goes Here");
dialog.SetNegativeButton("No", (sender, args) => { });
dialog.SetNeutralButton("Maybe", (sender, args) => { });
dialog.SetPositiveButton("Yes", (sender, args) => { });
dialog.Show();
Intents
• Activities are decoupled: they aren’t directly connected.
• You can use Intents to exchange messages with the
operating system or with another activity
• Very similar concept to messages in the MVVM pattern
Intents to launch another activity
• You use an intent to redirect the user to another page of
the application
• You pass, as parameter, the type of the destination
activity
var intent = new Intent(this, typeof(CallDetailActivity));
this.StartActivity(intent);
Type of the activity to create
Intents to pass data to another activity
• You can use Extras to pass data from one activity to
another
Value
var intent = new Intent(this, typeof(CallDetailActivity));
intent.PutStringArrayListExtra("phone_numbers", new[] { phoneNumberText.Text});
this.StartActivity(intent);
Key
Different Put methods to
support various data types
Intent to retrieve data from another activity
• You get the parameter in the OnCreate() method of the Activity
class
• It’s exposed by the Intent object
public class CallDetailActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
IList<string> parameters = Intent.Extras.GetStringArrayList("phone_numbers");
}
}
Key
KeyValue
Intents to launch built-in activities
• The Intent class can be used to launch a built-in activity
• Use the Intent enumerator to choose the activity’s type
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Android.Net.Uri.Parse("tel:" + phoneNumber));
StartActivity(callIntent);
The activity’s lifecicle
• Active: the activity is visible and running
• Paused: the device is in sleep mode, it’s kept in memory
• Backgrounded: the activity is no more in foreground, it’s kept in
memory if possible
• Restarted: the activity is created from scratch
The activity’s lifecicle
The Activity class offers
multiple methods to
override to manage the
different states of the
activity’s lifecycle
Configuration changes
• Android destroys and recreate the activity every time the
configuration changes:
– Orientation change
– Keyboard displayed
– Device connected to a dock
• It’s important to save the state of the activity, in case a
configuration change happens
Activities
DEMO
La prima app
Xamarin.Forms
Domanda 1
Per mostrare del contenuto ad un utente devo usare il seguente
controllo:
a) Page
b) Intent
c) Activity
d) Dialog
Domanda 1
Per mostrare del contenuto ad un utente devo usare il seguente
controllo:
a) Page
b) Intent
c) Activity
d) Dialog
Domanda 2
Per navigare tra diverse Activities uso:
a) Pointer
b) Intent
c) Navigator
d) Arrow
Domanda 2
Per navigare tra diverse Activities uso:
a) Pointer
b) Intent
c) Navigator
d) Arrow
Domanda 3
Un’Activity è composta dalle seguenti due componenti:
a) HTML + Code Behind (Java)
b) XML + Code Behind (C#)
c) UML + links
d) XAML + Code Behind (C#)
Domanda 3
Un’Activity è composta dalle seguenti due componenti:
a) HTML + Code Behind (Java)
b) XML + Code Behind (C#)
c) UML + links
d) XAML + Code Behind (C#)
Saving state
DEMO
Managing lists
Displaying lists
• ListView and GridView are used to display collections of
data
• They rely on the concept of adapter
to define the data to display
• Adapters are pieces of code that
create the UI for a row
Adapters
var pn = new List<string>();
pn.Add("Title 1");
pn.Add("Title 2");
pn.Add("Title 3");
ArrayAdapter
ArrayAdapter is a built-in adapter to display a collection of
strings.
await client.GetCharactersForSeriesAsync();
List<string> list = response.Results.Select(x => x.Name).ToList();
ListView listView = this.FindViewById<ListView>(Resource.Id.Comics);
listView.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1,
list);
Multiple layouts built-in
They are available using the enumerator
Android.Resource.Layout
Handling the selection
• Subscribe to the ItemClick event of the ListView
ListView listView = this.FindViewById<ListView>(Resource.Id.Comics);
listView.ItemClick += (sender, args) =>
{
...
};
listView.ItemClick += (sender, args) =>
{
string name = list[args.Position];
};
Lists
DEMO
La prima app
Xamarin.Forms
Domanda 1
Quali dei seguenti controlli possono essere utilizzati per mostrare una
lista?
a) ListView
b) ImageView
c) ComboBox
d) GridView
Domanda 1
Quali dei seguenti controlli possono essere utilizzati per mostrare una
lista?
a) ListView
b) ImageView
c) ComboBox
d) GridView
Domanda 2
Quali dei seguenti controlli possono essere utilizzati per mostrare una
lista?
a) ListView
b) ImageView
c) ComboBox
d) GridView
Domanda 2
Quali dei seguenti controlli possono essere utilizzati per mostrare una
lista?
a) ListView
b) ImageView
c) ComboBox
d) GridView
Custom adapters
• If you need to define a custom row layout, you need to use a
custom adapter
• A custom adapter needs to implement BaseAdapter<T>
• You need to implement the four required methods:
public abstract class BaseAdapter<T> : BaseAdapter
{
public abstract View GetView(int position, View convertView, ViewGroup parent);
public abstract T this[int position] { get; }
public abstract int Count { get; }
public abstract long GetItemId(int position);
}
LayoutInflator
• It’s a library class that takes the resource file and
returns a View hierarchy
• Every Activity has a LayoutInflator under the hood
<RelativeLayout ...>
<ImageView ... />
<TextView ... />
<TextView ... />
</RelativeLayout>
Creating a custom row
• The GetView() method of the custom adapter uses the
LayoutInflater to create the row starting from a layout
view = this.context.LayoutInflater.Inflate(Resource.Layout.CharacterRow,
parent, false);
<RelativeLayout ...>
<ImageView ... />
<TextView ... />
<TextView ... />
</RelativeLayout>
ListView Layout reuse
• ListView maintains the layouts only for the rows that are
visible to the user
• The GetView() method of the custom adapter will receive a
view to reuse if one is available
public override View GetView(int position, View convertView, ViewGroup parent)
{
//Cell reuse...
var view = convertView;
if (convertView == null)
{
view =
this.context.LayoutInflater.Inflate(Resource.Layout.CharacterRow, parent, false);
}
}
Custom lists
DEMO
La prima app
Xamarin.Forms
Domanda 1
Cosa devo implementare quando vado a realizzare un Custom
Adapter?
a) MyAdapter<T>
b) BaseAdapter<T>
c) CustomAdapter<T>
d) CommonAdapter<T>
Domanda 1
Cosa devo implementare quando vado a realizzare un Custom
Adapter?
a) MyAdapter<T>
b) BaseAdapter<T>
c) CustomAdapter<T>
d) CommonAdapter<T>
Working
with files
Files and folders
To create files and folder you can leverage the basic .NET APIs
(System.IO)
• Context.CacheDir
– Temporary files that can be deleted by the system anytime
• Context.ExternalCacheDir
– Temporary files that are removed when the app is deleted
• Android.OS.Environment.ExternalStorageDirectory.Path
– Access to external SD, it requires a capability in the manifest
• Environment.GetFolderPath(Environment.SpecialFolder.Per
sonal)
– Local storage of the application
Working with files
and folders
DEMO
Grazie per l’attenzione 
Guido Magrin
Xamarin Student Partner
@GuidoMagrin

More Related Content

What's hot

LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1Rich Helton
 
Refactor Large applications with Backbone
Refactor Large applications with BackboneRefactor Large applications with Backbone
Refactor Large applications with BackboneColdFusionConference
 
Android App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureAndroid App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureVijay Rastogi
 
I pad uicatalog_lesson02
I pad uicatalog_lesson02I pad uicatalog_lesson02
I pad uicatalog_lesson02Rich Helton
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
Automating the Gaps of Unit Testing Mobile Apps
Automating the Gaps of Unit Testing Mobile AppsAutomating the Gaps of Unit Testing Mobile Apps
Automating the Gaps of Unit Testing Mobile AppsGeoffrey Goetz
 
Android testing calabash
Android testing calabashAndroid testing calabash
Android testing calabashkellinreaver
 
Modular View Controller Hierarchies
Modular View Controller HierarchiesModular View Controller Hierarchies
Modular View Controller HierarchiesRené Cacheaux
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshareSaleemMalik52
 
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...JAX London
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Manoj Ellappan
 
Accessibility: A Journey to Accessible Rich Components
Accessibility: A Journey to Accessible Rich ComponentsAccessibility: A Journey to Accessible Rich Components
Accessibility: A Journey to Accessible Rich ComponentsAchievers Tech
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad ProgrammingRich Helton
 

What's hot (20)

Swift
SwiftSwift
Swift
 
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1LEARNING	 iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
LEARNING  iPAD STORYBOARDS IN OBJ-­‐C LESSON 1
 
Refactor Large applications with Backbone
Refactor Large applications with BackboneRefactor Large applications with Backbone
Refactor Large applications with Backbone
 
Xamarin Development
Xamarin DevelopmentXamarin Development
Xamarin Development
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Android App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureAndroid App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structure
 
I pad uicatalog_lesson02
I pad uicatalog_lesson02I pad uicatalog_lesson02
I pad uicatalog_lesson02
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
Synapseindia android apps application
Synapseindia android apps applicationSynapseindia android apps application
Synapseindia android apps application
 
React Native
React NativeReact Native
React Native
 
Automating the Gaps of Unit Testing Mobile Apps
Automating the Gaps of Unit Testing Mobile AppsAutomating the Gaps of Unit Testing Mobile Apps
Automating the Gaps of Unit Testing Mobile Apps
 
Android testing calabash
Android testing calabashAndroid testing calabash
Android testing calabash
 
Android cours
Android coursAndroid cours
Android cours
 
Modular View Controller Hierarchies
Modular View Controller HierarchiesModular View Controller Hierarchies
Modular View Controller Hierarchies
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Accessibility: A Journey to Accessible Rich Components
Accessibility: A Journey to Accessible Rich ComponentsAccessibility: A Journey to Accessible Rich Components
Accessibility: A Journey to Accessible Rich Components
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad Programming
 

Similar to Xamarin.Android Introduction

Android L and Wear overview
Android L and Wear overviewAndroid L and Wear overview
Android L and Wear overviewJames Montemagno
 
Android L and So Much More Webinar Slides
Android L and So Much More Webinar SlidesAndroid L and So Much More Webinar Slides
Android L and So Much More Webinar SlidesXamarin
 
Introduction to Android- A session by Sagar Das
Introduction to Android-  A session by Sagar DasIntroduction to Android-  A session by Sagar Das
Introduction to Android- A session by Sagar Dasdscfetju
 
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ....NET Conf UY
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkImam Raza
 
Mobile application development
Mobile application developmentMobile application development
Mobile application developmentumesh patil
 
Building your first android app using Xamarin
Building your first android app using XamarinBuilding your first android app using Xamarin
Building your first android app using XamarinGill Cleeren
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologiesjerry vasoya
 
Introduction to android mobile app development.pptx
Introduction to android mobile app development.pptxIntroduction to android mobile app development.pptx
Introduction to android mobile app development.pptxridzah12
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
The Great Mobile Debate: Native vs. Hybrid App Development
The Great Mobile Debate: Native vs. Hybrid App DevelopmentThe Great Mobile Debate: Native vs. Hybrid App Development
The Great Mobile Debate: Native vs. Hybrid App DevelopmentNick Landry
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UIXamarin
 
Android application development
Android application developmentAndroid application development
Android application developmentslidesuren
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app developmentAbhishekKumar4779
 

Similar to Xamarin.Android Introduction (20)

Android L and Wear overview
Android L and Wear overviewAndroid L and Wear overview
Android L and Wear overview
 
Android L and So Much More Webinar Slides
Android L and So Much More Webinar SlidesAndroid L and So Much More Webinar Slides
Android L and So Much More Webinar Slides
 
Introduction to Android- A session by Sagar Das
Introduction to Android-  A session by Sagar DasIntroduction to Android-  A session by Sagar Das
Introduction to Android- A session by Sagar Das
 
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
Tips & tricks for sharing C# code on iOS, Android and Windows Phone by Jaime ...
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
 
Intro to Android Programming
Intro to Android ProgrammingIntro to Android Programming
Intro to Android Programming
 
Android class provider in mumbai
Android class provider in mumbaiAndroid class provider in mumbai
Android class provider in mumbai
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
Building your first android app using Xamarin
Building your first android app using XamarinBuilding your first android app using Xamarin
Building your first android app using Xamarin
 
Android terminologies
Android terminologiesAndroid terminologies
Android terminologies
 
Introduction to android mobile app development.pptx
Introduction to android mobile app development.pptxIntroduction to android mobile app development.pptx
Introduction to android mobile app development.pptx
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
The Great Mobile Debate: Native vs. Hybrid App Development
The Great Mobile Debate: Native vs. Hybrid App DevelopmentThe Great Mobile Debate: Native vs. Hybrid App Development
The Great Mobile Debate: Native vs. Hybrid App Development
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
 
PPT Companion to Android
PPT Companion to AndroidPPT Companion to Android
PPT Companion to Android
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UI
 
Intro to android (gdays)
Intro to android (gdays)Intro to android (gdays)
Intro to android (gdays)
 
Android application development
Android application developmentAndroid application development
Android application development
 
Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app development
 
Android
Android Android
Android
 

More from Guido Magrin

Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#Guido Magrin
 
SQLite in Xamarin.Forms
SQLite in Xamarin.FormsSQLite in Xamarin.Forms
SQLite in Xamarin.FormsGuido Magrin
 
LGL Team - UniShare & UniBuy
LGL Team -  UniShare & UniBuyLGL Team -  UniShare & UniBuy
LGL Team - UniShare & UniBuyGuido Magrin
 
Evius Presentation
Evius PresentationEvius Presentation
Evius PresentationGuido Magrin
 
Enel Smart Info presentation
Enel Smart Info presentationEnel Smart Info presentation
Enel Smart Info presentationGuido Magrin
 
Xamarin.Forms Introduction
Xamarin.Forms IntroductionXamarin.Forms Introduction
Xamarin.Forms IntroductionGuido Magrin
 
Microsoft Azure Websites
Microsoft Azure WebsitesMicrosoft Azure Websites
Microsoft Azure WebsitesGuido Magrin
 
Introduction to Xamarin
Introduction to XamarinIntroduction to Xamarin
Introduction to XamarinGuido Magrin
 

More from Guido Magrin (8)

Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
SQLite in Xamarin.Forms
SQLite in Xamarin.FormsSQLite in Xamarin.Forms
SQLite in Xamarin.Forms
 
LGL Team - UniShare & UniBuy
LGL Team -  UniShare & UniBuyLGL Team -  UniShare & UniBuy
LGL Team - UniShare & UniBuy
 
Evius Presentation
Evius PresentationEvius Presentation
Evius Presentation
 
Enel Smart Info presentation
Enel Smart Info presentationEnel Smart Info presentation
Enel Smart Info presentation
 
Xamarin.Forms Introduction
Xamarin.Forms IntroductionXamarin.Forms Introduction
Xamarin.Forms Introduction
 
Microsoft Azure Websites
Microsoft Azure WebsitesMicrosoft Azure Websites
Microsoft Azure Websites
 
Introduction to Xamarin
Introduction to XamarinIntroduction to Xamarin
Introduction to Xamarin
 

Recently uploaded

WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

Xamarin.Android Introduction

  • 1. Creare app native su iOS, Android, Mac & Windows in C# Introduzione a Xamarin.Android
  • 2. Gli speaker di oggi Guido Magrin Xamarin & Microsoft Student Partner Xamarin Certified Developer @GuidoMagrin
  • 3. Dove trovo le slide? http://www.slideshare.net/guidomagrin
  • 4. Gli Xamarin Student Partner https://www.facebook.com/XSAMilano
  • 6. Chi ha già sentito parlare di Xamarin.Android?
  • 7. Xamarin + Xamarin.Forms Approccio offerto da Xamarin.Forms: Codice UI condiviso, controlli nativi Approccio tradizionale di Xamarin Shared UI Code
  • 8. .NET Android APIs | 100% coverage
  • 9. Qualsiasi cosa si possa fare in Java può essere fatta in C# con Xamarin in Visual Studio
  • 10. Xamarin Studio PC o Mac Plugin Visual Studio VS 2010 e superiore Ambienti di Sviluppo
  • 11. Integrazione in Visual Studio Una soluzione sola per: • iOS • Android • Windows Phone • Windows Store Tutti i plugin e le funzioni di Visual Studio: • ReSharper • Team Foundation Server
  • 12. Integrazione in Visual Studio Debugging su: • Emulatori • Dispositivi Integrati nella toolbar: • Stato • Logs • Lista di dispositivi
  • 13. Xamarin Studio • Ottimizzato per lo sviluppo cross-platform • Accedi alle API native con l’autocompletamento • Designer per Android e iOS • Debugging avanzato su emulatore o dispositivo
  • 14. Designer per Xamarin Android • Il migliore designer per Android • Disponibile per • Xamarin Studio • Visual Studio • Crea facilmente l’interfaccia utente tramite drag & drop • Affronta facilmente il problema del rescaling e della frammentazione di Android. • Layout salvati in file XML Android standard
  • 15. Cosa impareremo oggi? • The package • Activities • Liste
  • 17. The package The build process bundles the app into a single file with .apk extension. It’s the package that needs to be uploaded in the Google Store to publish the app.
  • 18. Permissions The manifest file controls which features of the platform the app can use.
  • 19. Images and screen density • Android runs on many devices with different screens and resolutions • You supply the images in different sizes with the same name • You distinguish them applying a naming convention to the folder where the image is stored
  • 20. Images and screen density • Every application should have an icon and a label • It’s set in the manifest file
  • 21. Icons and label • Also activities can have their own icon and label • They are displayed in the navigation bar • They are defined in the Activity attribute [Activity(Label = "AndroidFundamentals", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { ... }
  • 22. API levels • Every Android version is identified by: – Version number (4.4, 5.1, etc.) – Nickname (Kit Kat, Lollipop, etc.) – API Level (19, 22, etc.) • Every device supports a specific API level • It’s helpful to understand if an app can run on a specific device
  • 23. API levels • In the properties of the project you can define: – Target API: the API level used to build the package – Minimum API: the minimum set of supported API level – Target Android version: API level that the app expects to use • If API Level < Minimum API the app won’t be installed
  • 24. API Level Check • If API Level < Target API some APIs mightn’t be available • You can detect, in code, the current API Level: if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { //use APIs that are available in Lollipop } else { //fallback to old APIs }
  • 25. Resources • Resources can be managed using naming conventions applied to the folder • Examples: – resources/drawable-it: it contains the images used on an Italian device – layout-land: it contains the layouts to use in landscape mode • The Build Action must be set to AndroidResource
  • 26. Resources • Layout: interfaces • Drawable: images • Values: generic strings (localization) • Color: XML files that define colors
  • 29. Domanda 1 Un’applicazione Android funziona senza vincoli particolari su qualsiasi telefono sul quale sia installato Android: a) Vero b) Falso
  • 30. Domanda 1 Un’applicazione Android funziona senza vincoli particolari su qualsiasi telefono sul quale sia installato Android: a) Vero b) Falso
  • 31. Domanda 2 Come si chiama il file tramite il quale posso modificare le impostazioni di un package Android? a) Paper b) Resources c) Manifest d) Document
  • 32. Domanda 2 Come si chiama il file tramite il quale posso modificare le impostazioni di un package Android? a) Paper b) Resources c) Manifest d) Document
  • 33. Domanda 3 Quali sono i tipi di Resources disponibili in un’app Android? a) Layout, Images, Values, Brushes b) Layout, Drawables, Values, Color c) Disposition, Drawables, Enumerables, Color d) UIDefine, Images, Enumerables, Brushes
  • 34. Domanda 3 Quali sono i tipi di Resources disponibili in un’app Android? a) Layout, Images, Values, Brushes b) Layout, Drawables, Values, Color c) Disposition, Drawables, Enumerables, Color d) UIDefine, Images, Enumerables, Brushes
  • 36. Activities • An activity is a page that shows some content to the user. • An application is usually composed by multiple activities.
  • 37. Activities • In Xamarin, an Activity is composed by: – A XML file, that describes the layout (optional, it can be done also by code) – A code behind class, that manages the interactions with the UI <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...> <TextView ... /> <EditText ... /> <Button ... /> </LinearLayout> public class MainActivity : Activity { ... } UI defined with XML C# class that inherits from Activity and it’s decorated with the
  • 38. The Main Activity It’s the activity that is automatically launched when the user starts an app The MainLauncher property of the Activity attribute is used to define the main activity [Activity(MainLauncher = true] public class MainActivity : Activity { ... }
  • 39. Access to controls To gain access to a control in code you need to assign an ID Assign an ID in the XML <TextView android:id="@+id/PhoneNumber" /> // aapt resource value: 0x7f050000 public const int PhoneNumber = 2131034112; TextView phoneNumberView = this.FindViewById<TextView> (Resource.Id.PhoneNumber); The build process generates a resource You use the id to access to the control
  • 40. Dialogs The AlertDialog class is used to display modal messages var dialog = new AlertDialog.Builder(this); dialog.SetTitle("Title"); dialog.SetMessage("Message Goes Here"); dialog.SetNegativeButton("No", (sender, args) => { }); dialog.SetNeutralButton("Maybe", (sender, args) => { }); dialog.SetPositiveButton("Yes", (sender, args) => { }); dialog.Show();
  • 41. Intents • Activities are decoupled: they aren’t directly connected. • You can use Intents to exchange messages with the operating system or with another activity • Very similar concept to messages in the MVVM pattern
  • 42. Intents to launch another activity • You use an intent to redirect the user to another page of the application • You pass, as parameter, the type of the destination activity var intent = new Intent(this, typeof(CallDetailActivity)); this.StartActivity(intent); Type of the activity to create
  • 43. Intents to pass data to another activity • You can use Extras to pass data from one activity to another Value var intent = new Intent(this, typeof(CallDetailActivity)); intent.PutStringArrayListExtra("phone_numbers", new[] { phoneNumberText.Text}); this.StartActivity(intent); Key Different Put methods to support various data types
  • 44. Intent to retrieve data from another activity • You get the parameter in the OnCreate() method of the Activity class • It’s exposed by the Intent object public class CallDetailActivity : Activity { protected override void OnCreate(Bundle bundle) { IList<string> parameters = Intent.Extras.GetStringArrayList("phone_numbers"); } } Key KeyValue
  • 45. Intents to launch built-in activities • The Intent class can be used to launch a built-in activity • Use the Intent enumerator to choose the activity’s type var callIntent = new Intent(Intent.ActionCall); callIntent.SetData(Android.Net.Uri.Parse("tel:" + phoneNumber)); StartActivity(callIntent);
  • 46. The activity’s lifecicle • Active: the activity is visible and running • Paused: the device is in sleep mode, it’s kept in memory • Backgrounded: the activity is no more in foreground, it’s kept in memory if possible • Restarted: the activity is created from scratch
  • 47. The activity’s lifecicle The Activity class offers multiple methods to override to manage the different states of the activity’s lifecycle
  • 48. Configuration changes • Android destroys and recreate the activity every time the configuration changes: – Orientation change – Keyboard displayed – Device connected to a dock • It’s important to save the state of the activity, in case a configuration change happens
  • 51. Domanda 1 Per mostrare del contenuto ad un utente devo usare il seguente controllo: a) Page b) Intent c) Activity d) Dialog
  • 52. Domanda 1 Per mostrare del contenuto ad un utente devo usare il seguente controllo: a) Page b) Intent c) Activity d) Dialog
  • 53. Domanda 2 Per navigare tra diverse Activities uso: a) Pointer b) Intent c) Navigator d) Arrow
  • 54. Domanda 2 Per navigare tra diverse Activities uso: a) Pointer b) Intent c) Navigator d) Arrow
  • 55. Domanda 3 Un’Activity è composta dalle seguenti due componenti: a) HTML + Code Behind (Java) b) XML + Code Behind (C#) c) UML + links d) XAML + Code Behind (C#)
  • 56. Domanda 3 Un’Activity è composta dalle seguenti due componenti: a) HTML + Code Behind (Java) b) XML + Code Behind (C#) c) UML + links d) XAML + Code Behind (C#)
  • 59. Displaying lists • ListView and GridView are used to display collections of data • They rely on the concept of adapter to define the data to display • Adapters are pieces of code that create the UI for a row
  • 60. Adapters var pn = new List<string>(); pn.Add("Title 1"); pn.Add("Title 2"); pn.Add("Title 3");
  • 61. ArrayAdapter ArrayAdapter is a built-in adapter to display a collection of strings. await client.GetCharactersForSeriesAsync(); List<string> list = response.Results.Select(x => x.Name).ToList(); ListView listView = this.FindViewById<ListView>(Resource.Id.Comics); listView.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, list);
  • 62. Multiple layouts built-in They are available using the enumerator Android.Resource.Layout
  • 63. Handling the selection • Subscribe to the ItemClick event of the ListView ListView listView = this.FindViewById<ListView>(Resource.Id.Comics); listView.ItemClick += (sender, args) => { ... }; listView.ItemClick += (sender, args) => { string name = list[args.Position]; };
  • 66. Domanda 1 Quali dei seguenti controlli possono essere utilizzati per mostrare una lista? a) ListView b) ImageView c) ComboBox d) GridView
  • 67. Domanda 1 Quali dei seguenti controlli possono essere utilizzati per mostrare una lista? a) ListView b) ImageView c) ComboBox d) GridView
  • 68. Domanda 2 Quali dei seguenti controlli possono essere utilizzati per mostrare una lista? a) ListView b) ImageView c) ComboBox d) GridView
  • 69. Domanda 2 Quali dei seguenti controlli possono essere utilizzati per mostrare una lista? a) ListView b) ImageView c) ComboBox d) GridView
  • 70. Custom adapters • If you need to define a custom row layout, you need to use a custom adapter • A custom adapter needs to implement BaseAdapter<T> • You need to implement the four required methods: public abstract class BaseAdapter<T> : BaseAdapter { public abstract View GetView(int position, View convertView, ViewGroup parent); public abstract T this[int position] { get; } public abstract int Count { get; } public abstract long GetItemId(int position); }
  • 71. LayoutInflator • It’s a library class that takes the resource file and returns a View hierarchy • Every Activity has a LayoutInflator under the hood <RelativeLayout ...> <ImageView ... /> <TextView ... /> <TextView ... /> </RelativeLayout>
  • 72. Creating a custom row • The GetView() method of the custom adapter uses the LayoutInflater to create the row starting from a layout view = this.context.LayoutInflater.Inflate(Resource.Layout.CharacterRow, parent, false); <RelativeLayout ...> <ImageView ... /> <TextView ... /> <TextView ... /> </RelativeLayout>
  • 73. ListView Layout reuse • ListView maintains the layouts only for the rows that are visible to the user • The GetView() method of the custom adapter will receive a view to reuse if one is available public override View GetView(int position, View convertView, ViewGroup parent) { //Cell reuse... var view = convertView; if (convertView == null) { view = this.context.LayoutInflater.Inflate(Resource.Layout.CharacterRow, parent, false); } }
  • 76. Domanda 1 Cosa devo implementare quando vado a realizzare un Custom Adapter? a) MyAdapter<T> b) BaseAdapter<T> c) CustomAdapter<T> d) CommonAdapter<T>
  • 77. Domanda 1 Cosa devo implementare quando vado a realizzare un Custom Adapter? a) MyAdapter<T> b) BaseAdapter<T> c) CustomAdapter<T> d) CommonAdapter<T>
  • 79. Files and folders To create files and folder you can leverage the basic .NET APIs (System.IO) • Context.CacheDir – Temporary files that can be deleted by the system anytime • Context.ExternalCacheDir – Temporary files that are removed when the app is deleted • Android.OS.Environment.ExternalStorageDirectory.Path – Access to external SD, it requires a capability in the manifest • Environment.GetFolderPath(Environment.SpecialFolder.Per sonal) – Local storage of the application
  • 80. Working with files and folders DEMO
  • 81. Grazie per l’attenzione  Guido Magrin Xamarin Student Partner @GuidoMagrin

Editor's Notes

  1. We see here the Xamarin approach we talked about earlier This enables you to be highly productive, share code, but build out UI on each platform and access platform APIs With Xamarin.Forms you now have a nice Shared UI Code layer, but still access to platform APIs You can start from native, pick a few screens, or start with forms, and replace with native later
  2. E anche in Android tutte le API sono state coperte.
  3. Xamarin Studio PC -> Android Mac -> iOS, Android, Mac Visual Studio: iOS, Android Windows
  4. Il plugin supporta Visual Studio 2010, 2012, 2013 e 2015 Supporta le desktop app su Windows: WPF, ASP.NET, Silverlight, WinForms Soluzioni e progetti possono esssere aperti indistintamente in Xamarin Studio e Visual Studio
  5. AGGIORNARE SCREEN
  6. Xamarin Studio su PC consente solamente Android, su Mac Android, iOS e Mac. Xamarin Studio consente di lavorare con Git e altri sistemi di source control.
  7. Xamarin Introduction!
  8. Xamarin Introduction!
  9. Xamarin Introduction!
  10. Xamarin Introduction!
  11. Xamarin Introduction!
  12. Xamarin Introduction!
  13. Xamarin Introduction!
  14. Xamarin Introduction!
  15. Xamarin Introduction!
  16. Xamarin Introduction!
  17. Xamarin Introduction!