You are on page 1of 39

Android Beginners Workshop

at the

M O B ! " M O # D $%

D E V E L O P E R D AY

& 2d2

Febr'ar() 2*th 2010 +,en -olt&ann) $ndroidP .

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

Sven Woltmann

+t'died /o&p'ter +0ien0e at the .1 l&ena') 1223-1222 12 (ear 4a,a e5perien0e) 26 (ears total progra&&ing e5perien0e Fo'nded se,eral start-'ps together with Fabien 78hlinger De,eloped se,eral prod'0ts) whi0h are still in 'se toda( 4oined $ndroidP . in $'g'st 2002 De,eloped a new /M+ for the $ndroidP . website De,eloped the $ndroidP . $pp

"-&ail: s,en.wolt&ann9androidpit.de

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

AndroidPIT (www.androidpit.de)

Dail( test reports :; 300< Dail( news /o&&'nit( :; =.000 &e&bers< For'& :; *)000 topi0s< -iki Market apps database :; *0)000< "nglish ,ersion in 0*/2010

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

AndroidPIT App

$ll test reports $ll news $ll for'& posts More to 0o&e...

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

Contents of the Workshop


1. $ndroid app basi0s 2. De,elop&ent en,iron&ent re>'ire&ents *. +etting 'p the de,elop&ent en,iron&ent (not part of the live presentation) 3. De,eloping and testing a ?@ello -orldA app 6. B'estions

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

1. Android App Basi s


$ndroid apps are written in 4a,a $l&ost all 4a,a 0lasses a,ailable pl's en0r(ption) http) Cson) 5&l pro0essing libraries #o &ain:< f'n0tion D instead: loosel( 0o'pled 0o&ponents) one or &ore of the& defined as entr( point:s< Most i&portant 0o&ponent: ?$0ti,it(A D 0orresponds to a ,isible window on the s0reen

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

1. Android App Basi s ! A tivit"# $iew# %vent# Intent


$0ti,it( Defines a ?EiewA to be displa(ed in its window @andles e,ents :e.g. 0li0k on a b'tton< 1ses ? ntentsA to start other a0ti,ities Eiew $ ?EiewA is the ,isible part of the a0ti,it( Defined in an FM! la(o't file :or in 0ode< ntent +tarts another a0ti,it( :?opens a new windowA< /an pass data to the started a0ti,it( /an e,en start a0ti,ities fro& another app More in the workshop ?De,eloping $ndroid ntentsA
$0ti,it(
cl as s M yA c t ivi ty ex te nd s Act i v it y { on Cr ea te () Defines view { Vi ew vi ew = se tCo nt en t V iew ( v ie w) ; }
Event on Cl ic k( ) { In ten t in t e nt = st art Ac ti v i ty( i n te nt ); }

Eiew

B'tton

} Uses intent to start another activity

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

1. Android App Basi s ! A tivit" &ife " le


$s reso'r0es are li&ited on a &obile phone) the operating s(ste& &'st be able to destro( an a0ti,it() whi0h is not a0ti,e :&eaning: in the foregro'nd of the s0reen<) at an( ti&e. .herefore) e,er( $0ti,it( has a life0(0le whi0h is handled b( the $ndroid operating s(ste&. .o a,oid losing data or the state of an a0ti,it() (o' &'st o,erride life0(0le &ethods to sa,e (o'r data when (o'r a0ti,it( is pa'sed :not in the foregro'nd an(&ore b't still ,isible< or stopped :not ,isible an(&ore<.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

'. (evelopment %nvironment )e*+irements


1. "0lipse 2. $ndroid +DG +tarter Pa0kage fro& http://de,eloper.android.0o&/sdk/inde5.ht&l *. 1se +DG +tarter Pa0kage :r'n as $d&inistrator< to install: - +DGs for all platfor&s (o'r app shall be r'nning on :e.g. all fro& 1.6 to 2.1< - 1+B Dri,er Pa0kage for 1+B deb'gging :deb'g apps dire0tl( on (o'r phone< 3. $D. :$ndroid De,elop&ent .ools< "0lipse Pl'gin : nstall fro& within "0lipseH lo0ation: https://dl-ssl.google.0o&/android/e0lipse/< -hat is the $D. good forI J -iKard to 0reate a new $ndroid proCe0t J /ode editor for $ndroid FM! files J $'to&ati0 b'ild pro0ess :0reates $PG ?$ndroid Pa0kageA file< J Deb'gging of apps in the e&'lator or on a real phone J .ake s0reenshots fro& a real phone J "5port signed $PGs to be 'ploaded into $ndroid Market

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

,. Setting +p the (evelopment %nvironment (1-,)


1. "0lipse is e5pe0ted to be installed. 2. Download and install the +DG +tarter Pa0kage appropriate to (o'r operating s(ste& fro& http://de,eloper.android.0o&/sdk/inde5.ht&l *. 7'n +DG +tarter Pa0kage :as $d&inistrator on Eista / -indows L<. nstall... - all +DG platfor&s :for this t'torial) 1.M is eno'gh<) - the 1+B dri,er pa0kage :not re>'ired for this t'torial<) - and the do0'&entation :not re>'ired for this t'torial<.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

,. Setting +p the (evelopment %nvironment ('-,)


3. nstall the $D. :$ndroid De,elop&ent .ools< pl'gin. .he following instr'0tions are for "0lipse *.6 :Nalileo< and "0lipse *.M :@elios<. nstr'0tions for "0lipse *.3 :Nan(&ede< 0an be fo'nd at http://de,eloper.android.0o&/sdk/e0lipse-adt.ht&l. 3.1. +ele0t ?@elpA J ? nstall #ew +oftwareA. 3.2. n the ?$,ailable +oftwareA dialog) 0li0k the ?$ddA b'tton... 3.*. n the ?$dd +iteA dialog) enter a na&e :e.g.?$ndroid Pl'ginA< and the following 17! as lo0ation: https://dl-ssl.google.0o&/android/e0lipse/ :tr( ?httpA) if ?httpsA does not work<. /li0k the ?OGA b'tton.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

,. Setting +p the (evelopment %nvironment (,-,)


3.3. Ba0k in the ?$,ailable +oftwareA dialog) sele0t the 0he0kbo5 ne5t to ?De,eloper .oolsA and 0li0k ?#e5tA. 3.6. n the ? nstall DetailsA dialog) 0li0k ?#e5tA to a00ept the li0ense $gree&ent) then 0li0k ?FinishA. 3.M. 7estart "0lipse. 3.L. +ele0t ?-indowA J ?Preferen0esA. 3.=. n the ?Preferen0esA dialog) sele0t ?$ndroidA. 3.2. "nter the +DG folder :e.g. ?/:OProgra&&eOandroid-sdk-windowsA< and 0li0k ?OGA.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (1-'')


1se the $D.Ps ?#ew ProCe0tA wiKard to 0reate a new proCe0t: +ele0t ?FileA J ?#ewA J ?ProCe0t...AH in the ?#ew ProCe0tA dialog sele0t ?$ndroid ProCe0tA fro& the ?$ndroidA folder. Fill o't the ?#ew $ndroid ProCe0tA dialog as follows: ProCe0t na&e: ?@ello -orkshopA 1se defa'lt lo0ation or define (o'r own lo0ation B'ild target: $ndroid 1.M :wePll &ake this 1.6-0o&patible later< $ppli0ation na&e: ?@ello -orkshopA Pa0kage na&e: ?de.test.helloA /reate $0ti,it(: ?@ello-orkshop$0ti,it(A Min +DG Eersion: ?3A /li0k on the ?FinishA b'tton.
Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App ('-'')


.he ?#ew ProCe0tA -iKard 0reated the following files and folders:

Main $0ti,it( 0lass 7eso'r0e D definitions :a'to-0reatedH ne,er &odif( this file< Folder for binar( files :e,er(thing not handled b( $ndroid< Folder for reso're files :i&ages) la(o'ts) strings) ...< !ogo in high resol'tion :L2 b( L2 pi5els D 230 dpi< !ogo in low resol'tion :*M b( *M pi5els D 120 dpi< !ogo in &edi'& resol'tion :3= b( 3= pi5els D 1M0 dpi< !a(o't definition for &ain a0ti,it(Ps ,iew +tring definitions ?Manifest fileA defining things like app na&e) logo and &ain a0ti,it( ProCe0t properties
Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (,-'')


Android0anifest.1ml Base pa0kage na&e
<?x l version="1.0" encodin!="utf-8"?" < ani#est x lns$android="http://schemas.android.com/apk/res/android" %acka!e="de.test.hello" 7eferen0e to i0on in drawable-555 folders android$versionCode="1" 7eferen0e to appQna&e in strings.5&l android$version&a e="1.0"" <a%%lication android$icon="@drawable/icon" android$la'el="@string/app_name"" <activity android$na e=".Hello orkshop!cti"it#" android$la'el="@string/app_name"" <intent(#ilter" <action android$na e="android.intent.action.$!%&" )" <cate!ory android$na e="android.intent.categor#.'!(&)H*+" )" <)intent(#ilter" <)activity" <)a%%lication" <*ses(sdk android$ in+dkVersion="," )" <) ani#est"

#'&eri0 ,ersion 0ode) in0rease with new ,ersion Eersion na&e displa(ed in Market

Main a0ti,it(Ps 0lass na&e Main a0ti,it(Ps label :at the top of the s0reen< ntent filter to define that this a0ti,it( 0an be la'n0hed fro& the la'n0h &en'

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (.-'')


For phones with high densit( s0reens :e.g. Motorola Milestone< to 'se the hdpi reso'r0es) we &'st add the following entr( to the $ndroidManifest.5&l file: <s*%%orts(screens android$any,ensity="true" )" Otherwise) those phones will 'se the &dpi reso'r0es and s0ale the& 'p. For phones with large :$r0hos 6< or s&all s0reens :@./ .attoo< to 'se the f'll s0reen or to r'n the app at all) we &'st f'rther add the following definitions to the entr( 0reated before: <s*%%orts(screens android$any,ensity="true" android$lar!e+creens="true" android$s all+creens="true" )" Otherwise) phones with large s0reens will displa( the app onl( in a s&all area of the s0reen with a bla0k border aro'nd it) and phones with s&all s0reens wonPt start the app at all.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (2-'')


val+es-strings.1ml <?x l version="1.0" encodin!="utf-8"?" <reso*rces" <strin! na e="hello""-ello .orld/ -ello.orks0o%Activity1<)strin!" <strin! na e="app_name""-ello .orks0o%<)strin!" <)reso*rces" Defines strings) referen0ed b( the &anifest and la(o't file :0an also be referen0ed b( 0ode<: android$la'el="@string/app_name"-is e>'i,alent to android$la'el="Hello- orkshop" Of 0o'rse onl( as long as we donPt add strings.xml files in other lag'ages. f (o' plan to lo0aliKe (o'r app) (o' sho'ld alwa(s p't all strings into reso'r0e files.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (3-'')


la"o+t-main.1ml <?x l version="1.0" encodin!="utf-8"?" <2inear2ayo*t x lns$android="http://..../" android$orientation=""ertical" android$layo*t3widt0="fill_parent" android$layo*t30ei!0t="fill_parent" " <4extView android$layo*t3widt0="fill_parent" android$layo*t30ei!0t="wrap_content" android$text="@string/hello" )" <)2inear2ayo*t" Defines a :si&ple< la(o't 0alled ?&ainA :C'st a na&e) no &eaning<) whi0h is later referen0ed b( the a0ti,it( to 0reate its ,iew.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (4-'')


).5ava $'to&ati0all( 0reated D defines integer 0onstants for ea0h reso'r0e. #e,er &odif( this file D no need to e,en look at it.
%acka!e de5test50ello; %*'lic #inal class 6 { %*'lic static #inal class attr { } %*'lic static #inal class drawa'le { %*'lic static #inal int icon=7x8#797777; } %*'lic static #inal class layo*t { %*'lic static #inal int main=7x8#7:7777; } %*'lic static #inal class strin! { %*'lic static #inal int app_name=7x8#7;777<; %*'lic static #inal int hello=7x8#7;7777; } }
Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (6-'')


/elloWorkshop'A tivit".5ava %acka!e de5test50ello; i %ort android5a%%5Activity; i %ort android5os5=*ndle; %*'lic class -ello.orks0o%Activity extends Activity { )>> Called w0en t0e activity is #irst created5 >) ?@verride %*'lic void onCreate(=*ndle savedInstance+tate) { s*%er5onCreate(savedInstance+tate); setContentView(65layo*t5main); } } /onstant fro& 7 0lass referen0ing the la(o't defined in &ain.5&l +ets the spe0ified ,iew as ,iew for this a0ti,it(.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (9-'')


Create an 7Android $irt+al (evi e8 (%m+lator)

/li0k on the ?$ndroid +DG and $ED &anagerA i0on in the "0lipse i0on bar. /li0k on ?#ewA n the ?/reate new $EDA dialog) enter: - #a&e: ?N1A - .arget: ?$ndroid 1.M - $P !e,el 3A - +D /ard +iKe: ?1023A MiB - +kin: B'ilt-in: ?Defa'lt :@EN$<A then 0li0k on ?/reate $EDA :&ight take a while now<

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (1:-'')


)+n the App for the ;irst Time

+ele0t ?7'nA J ?7'nA :or press /trl R F11<. n the ?7'n $sA dialog) sele0t ?$ndroid $ppli0ationA and 0li0k on ?OGA. "0lipse will now a'to&ati0all( start the ?N1A $ED we C'st 0reated :if (o' ha,e &'ltiple &at0hing $EDs) a sele0tion dialog will let (o' 0hose one<. $fter abo't a &in'te we sho'ld see o'r app r'nning in the e&'latorS

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (11-'')


@ello -orld) @ello-orkshop2$0ti,it(S "nter (o'r na&e:

.his is what we want to do toda(:

/reate a ,iew that looks like the one at the left !et the 'ser enter his na&e in the inp't field -hen the 'ser 0li0ks one of the b'ttons and no na&e was entered) displa( an alert dialog with an error &essage. -hen the 'ser 0li0ks a b'tton with his na&e entered J the 'ser shall be greeted with a pop'p &essage :?toastA< J the greeting at the top of the s0reen shall 0hange

+a( @iS

+a( @elloS

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (1'-'')


Add Components to the &a"o+t $dd the ?"nter (o'r na&eA label below the first .e5tEiew 0o&ponent:
<4extView android$layo*t3widt0="fill_parent" android$layo*t30ei!0t="wrap_content" android$layo*t3 ar!in4o%="00dp" android$text="@string/enter_#our_name" --)"

"0lipse will now show an error &essage: ?#o reso'r0e fo'nd that &at0hes the gi,en na&e :at Pte5tP with ,al'e P9string/enterQ(o'rQna&eP<. $dd the &issing reso'r0e to the strings.5&l file:
<strin! na e="enter_#our_name""Anter yo*r na e$<)strin!"

.he error &essage fro& &ain.5&l will now disappear.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (1,-'')


$dd the inp't field below the ?"nter (o'r na&eA 0o&ponent: <Adit4ext android$id="@1id/name_field" android$layo*t3widt0="fill_parent" android$layo*t30ei!0t="wrap_content" )" .he first line assigns the id ?na&eQfieldA to this 0o&ponent. Below the na&e field we want to b'ttons beside ea0h other. .herefore we need a nested !inear!a(o't with horiKontal orientation) and inside it the two b'ttons.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (1.-'')


#ested !inear!a(o't with two B'ttons: $dd the b'tton te5ts to the strings.5&l file:
<2inear2ayo*t <strin! na e="hi_button""+ay -i1<)strin!" android$orientation="hori2ontal" <strin! na e="hello_button""+ay -ello1<)strin!" android$layo*t3widt0="fill_parent" android$layo*t30ei!0t="wrap_content" " <=*tton android$id="@1id/hi_button" android$layo*t3widt0="wrap_content" android$layo*t30ei!0t="wrap_content" android$layo*t3wei!0t="1" android$text="@string/hi_button" )" <=*tton android$id="@1id/hello_button" android$layo*t3widt0="wrap_content" android$layo*t30ei!0t="wrap_content" android$layo*t3wei!0t="1" android$text="@string/hello_button" )" <)2inear2ayo*t"
Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (12-'')


!etPs ha,e a look at the la(o'tS n the &ain.5&l tab in "0lipse) 0li0k on the ?!a(o'tA tab at the botto&) and (o' will see the following:

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (13-'')


#ow we need to e5tend o'r $0ti,it(. Open @ello-orkshop$0ti,it(.Ca,a and add the following field definitions at the top of the 0lass:
%rivate =*tton 0i=*tton; %rivate =*tton 0ello=*tton;

$t the end of the on/reate &ethod) insert the following 0ode:


0i=*tton = (=*tton)#indView=yId(65id5hi_button); 0i=*tton5set@nClick2istener(t0is); 0ello=*tton = (=*tton)#indView=yId(65id5hello_button); 0ello=*tton5set@nClick2istener(t0is);

-e will now see an error &essage as @ello-orkshop$0ti,it( does not i&ple&ent On/li0k!istener (et. /li0k on the error &essage and sele0t ?!et P@ello-orkshop$0ti,it(P i&ple&ent POn/li0k!istenerP.A -ePll see the ne5t error &essage be0a'se @ello-orkshop$0ti,it( does not i&ple&ent the &ethods defined in On/li0k!istener. /li0k on the error &essage and sele0t ?$dd 'ni&ple&ented &ethodsA.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (14-'')


-hen the 'ser 0li0ks on one of the b'ttons) we first need to 0he0k if he entered his na&e. nsert the following 0ode into the ?on/li0kA &ethod "0lipse has C'st 0reated for 's:
Adit4ext na eBield = (Adit4ext) #indView=yId(65id5name_field); +trin! na e = na eBield5!et4ext()5to+trin!(); i# (na e5len!t0() == 7) { new Alert,ialo!5=*ilder(t0is) 5setMessa!e(65strin!5error_name_missing) 5set&e*tral=*tton(65strin!5error_ok/ n*ll) 5s0ow(); ret*rn; }

$dd the two string reso'r0es we C'st 'sed and two others we 'se in the ne5t step to the strings.5&l file:
<strin! <strin! <strin! <strin! na na na na e="error_name_missing""Clease enter yo*r na e5<)strin!" e="error_ok""@D<)strin!" e="hi_greeting""-i Es1<)strin!" e="hello_greeting""-ello Es1<)strin!"

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (16-'')


-eP,e &ade s're the 'ser entered a na&e. #ow displa( the greeting depending on the b'tton: i# (v == 0i=*tton FF v == 0ello=*tton) { int reso*rceId = v == 0i=*tton ? 65strin!5hi_greeting $ 65strin!5hello_greeting; +trin! !reetin! = !et6eso*rces()5!et+trin!(reso*rceId/ na e); 4oast5make3e4t(t0is/ !reetin!/ 4oast5'*&53H_'6&5)5s0ow();

Finall() we want the greeting at the top of the s0reen to be 0hanged. .o 0hange the te5t of that 0o&ponent) we first &'st assign an D to it. +o edit the &ain.5&l file and insert the id into the first .e5tEiew ele&ent: <4extView android$id="@1id/greeting_field" ----7-/8

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (19-'')


.he &ethod weP,e C'st 0reated 0an now be e5tended: i# (v == 0i=*tton FF v == 0ello=*tton) { int reso*rceId = v == 0i=*tton ? 65strin!5hi_greeting $ 65strin!5hello_greeting; +trin! !reetin! = !et6eso*rces()5!et+trin!(reso*rceId/ na e); 4oast5make3e4t(t0is/ !reetin!/ 4oast5'*&53H_'6&5)5s0ow(); 4extView !reetin!Bield = (4extView) #indView=yId(65id5greeting_field); !reetin!Bield5set4ext(!reetin!);

$nd nowI -ePre read( - r'n the proCe0tS %o'Pll find the 0o&plete so'r0es in the appendi5.

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (':-'')

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App ('1-'')


0aking the pro5e t ompati<le for Android 1.2 (e.g. /TC /ero) n $ndroid 1.M) different s0reen resol'tions and densities were introd'0ed. Before $ndroid 1.6) the folders drawable-hdpi) drawable-ldpi) drawable-&dpi where not known. J 7ena&e folder ?drawable-hdpiA to ?drawable-hdpi-,3A) so $ndroid 1.6 and lower will ignore it J 7ena&e folder ?drawable-ldpiA to ?drawable-ldpi-,3A) so $ndroid 1.6 and lower will ignore it J 7ena&e folder ?drawable-&dpiA to ?drawableA) so $ndroid 1.6 will see it n $ndroidManifest.5&l 0hange the line <*ses(sdk android$ in+dkVersion="," )" to <*ses(sdk android$ in+dkVersion="9" tar!et+dkVersion="," )"

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

.. (eveloping and Testing a /ello World App (''-'')


Where to go from here= - No to the other workshops - /reate different la(o'ts for different s0reen orientations - $dd a se0ond $0ti,it( and start that fro& the e5isting $0ti,it( :for e5a&ple b( 0li0king on a new b'tton< - Pla( aro'nd with other la(o'ts :http://de,eloper.android.0o&/reso'r0es/t'torials/,iews/inde5.ht&l< - /he0k o't all the other t'torials on http://de,eloper.android.0o&

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

2. >+estions

I I I
Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

Thank ?o+@
!inks: http://www.androidpit.de/ http://www.androidpit.de/de/android/for'& http://www.androidpit.de/de/android/&arket/apps/app/de.androidpit.app/$ndroidP .

Offi0ial page with t'torials and e5a&ples:

http://de,eloper.android.0o&/

.his presentation:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

Appendi1 ! So+r e Codes


@ello-orkshop$0ti,it(.Ca,a:
package de.test.hello; import android.app.Activity; import android.app.AlertDialog; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Edit e!t; import android.widget. e!tView; import android.widget. oast; pu"lic class #ello$orkshopActivity e!tends Activity implementsOnClickListener % private Button hiButton ; private Button helloButton ; &Override pu"lic void onCreate'Bundle saved(nstance)tate* % super .onCreate'saved(nstance)tate*; setContentView'+.layout. main*; hiButton , 'Button* -indViewBy(d'+.id. hi_button *; hiButton . setOnClickListener' this *; helloButton, 'Button* -indViewBy(d'+.id. hello_button *; helloButton .setOnClickListener' this*; . . . . &Override pu"lic void onClick'View v* % Edit e!t name/ield , 'Edit e!t* -indViewBy(d'+.id. name_field *; )tring name , name/ield.get e!t'*.to)tring'*; i- 'name.length'* ,, 0* % new AlertDialog.Builder' this *.set1essage' +.string. e rror_name_missing *.set2eutralButton' +.string. e rror_ok 3 null*.show'*; return ; . i- 'v ,, hiButton 44 v ,, helloButton * % int resource(d , v ,, hiButton 5 +.string. hi_greeting 6 +.string. hello_greeting ; )tring greeting , get+esources'*.get)tring'resource(d3 name*; oast. makeText 'this 3 greeting3 oast. LENGTH_LONG *.show'*; e!tView greeting/ield , ' e!tView* -indViewBy(d'+.id. greeting_field *; greeting/ield.set e!t'greeting*;

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

Appendi1 ! So+r e Codes


&ain.5&l
75!ml version ,"1.0" encoding ,"utf- " 58 7LinearLayout !mlns6android ,"htt!"##s$hemas.android.$om#a!k#res#android" android6orientation ,"%erti$al" android6layout9width ,"fill_!arent" android6layout9height ,"fill_!arent" 8 7 e!tView android6id ,"&'id#greeting_field" android6layout9width ,"fill_!arent" android6layout9height ,"(ra!_$ontent" android6te!t ,"&string#hello" :8 7 e!tView android6layout9width ,"fill_!arent" android6layout9height ,"(ra!_$ontent" android6layout9margin ,op ")0d!" android6te!t ,"&string#enter_*our_name" :8 7Edit e!t android6id ,"&'id#name_field" android6layout9width ,"fill_!arent" android6layout9height ,"(ra!_$ontent" :8 7LinearLayout android6orientation ,"hori+ontal" android6layout9width ,"fill_!arent" android6layout9height ,"(ra!_$ontent" 8 7Button android6id ,"&'id#hi_button" android6layout9width ,"(ra!_$ontent" android6layout9height ,"(ra!_$ontent" android6te!t ,"&string#hi_button" android6layout9weight ,"1" :8 7Button android6id ,"&'id#hello_button" android6layout9width ,"(ra!_$ontent" android6layout9height ,"(ra!_$ontent" android6te!t ,"&string#hello_button" android6layout9weight ,"1" :8 7:LinearLayout 8 7:LinearLayout 8

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

Appendi1 ! So+r e Codes


strings.5&l
75!ml version ,"1.0" encoding ,"utf- " 58 7resources 8 7string name ,"hello" 8#ello $orld3 #ello$orkshopActivity; 7:string 8 7string name ,"a!!_name" 8#ello $orkshop 7:string 8 7string name ,"enter_*our_name" 8Enter your name6 7:string 8 7string name ,"hi_button" 8)ay #i; 7:string 8 7string name ,"hello_button" 8)ay #ello; 7 :string 8 7string name ,"error_name_missing" 8<lease enter your name. 7:string 8 7string name ,"error_ok" 8O=7:string 8 7string name ,"hi_greeting" 8#i >s; 7:string 8 7string name ,"hello_greeting" 8#ello >s; 7 :string 8 7:resources 8

Download this presentation as PDF:

http://www.androidpit.de/files/androidpit-beginners-workshop-2010.pdf

You might also like