PROYECTO FINAL. Tutorial para publicar en SlideShare.pptx
Android Bootcamp - GTUG Uruguay
1. Mi primera Aplicación Android ¡¡¡Bienvenidos!!! Setiembre 2011 Gabriel Kouyoumdjian Gabriel Olivera
2. GTUGs: Google Tecnology User Groups Android, AppEngine, APIs de productos, developer tools, proyectos open source 267 #capítulos (activos + incubando) 545 #eventos en los últimos seis meses En Uruguay: uy-gtug.org
11. Instalación del Plugin ADT En Eclipse: Help -> Install New Software.... -> Add Name: Android Plugin Archivo: ADT-12.0.0.zip (en la carpeta BOOTCAMP) [x] Developer Tools [ ] DESMARCAR "Check all update sites..." Next, next, next....., restart.
12. Configurar Ubicación de la SDK En Eclipse: Preferences -> Android SDK Location: BOOTCAMP/android-sdk.../ Click en "Apply" Click en "OK"
13. Crear un nuevo Emulador Window -> AVD Manager -> Virtual Devices->New Name: MyAVD Target: Android 2.1 Resolution/Built-In: HVGA Create AVD Close
14. Proyecto Hello World File -> New -> Android Project Project Name: Hello World Build Target: Android 2.1 Properties: Application Name: Hello World Package Name: com.example.helloworld Create Activity: HelloActivity
38. Experimento Porque Android hace lo que llamamos "Activity Lifecycle Management" ...y puede mantener activas o cerrar las Activities de acuerdo a las necesidades
39. Experimento 2 Cerrar la aplicación (presionando "Home") Forzar el cierre de la aplicación a través del menú Menu -> Manage Apps -> Hello World -> Force Stop Iniciar nuevamente a partir del menú de aplicaciones. ¿Cuál es el resultado esta vez?
48. El "Toast" que aparece al hacer click en la lista tampoco está muy bueno... ¿Cómo se pode implementar una búsqueda en la Web en vez del Toast?
49. ... HelloActivity.java [7] public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { Uri uri = Uri.parse(" http :// www.google.com/search?hl=en&q= " + Uri.encode(countries.get(pos), null) + "&btnI= " + Uri.encode("I'm Feeling Lucky")); Intent intent = new Intent( Intent. ACTION_VIEW , uri); startActivity(intent); }
50. Referencias: Elaborado (con adaptaciones) a partir de los tutoriales: http://developer.android.com/resources/tutorials/hello-world.html http://developer.android.com/resources/tutorials/views/index.html
51. ¡Gracias! ¡¡¡Hasta la próxima!!! Gabriel Kouyoumdjian (gabriel.kb@gtugs.org) Gabriel Olivera (gabriel.olivera@gtugs.org)
onCreate() Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one. Always followed by onStart(). setContentView(): Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy. It can itself be a complex view hierarchy. link to http://developer.android.com/images/activity_lifecycle.png?
fill_parent : means that the view wants to be as big as its parent (minus padding) wrap_content : means that the view wants to be just big enough to enclose its content (plus padding) String Resources: In Java: R.string. string_name In XML:@string/ string_name
dp: Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both &quot;dip&quot; and &quot;dp&quot;, though &quot;dp&quot; is more consistent with &quot;sp&quot;. sp: Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
@+id/ means that we are creating this id in the namespace of our application
R.id.mylistview references entity declared on Resource file Toast: A toast is a view containing a quick little message for the user. The toast class helps you create and show those. ArrayAdapter: A concrete BaseAdapter that is backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource.
Note that the width of EditText is defined in sp
?
getPreferences() : Retrieve a SharedPreferences object for accessing preferences that are private to this activity. MODE_PRIVATE : File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID). MODE_WORLD_READABLE: File creation mode: allow all other applications to have read access to the created file MODE_WORLD_WRITABLE: File creation mode: allow all other applications to have write access to the created file.
Second argument in sp.getString(&quot;countries&quot;, &quot;Brazil;Argentina;Mexico&quot;); is the default value
Intent: An intent is an abstract description of an operation to be performed. An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed. The primary pieces of information in an intent are: action -- The general action to be performed, such as ACTION_VIEW , ACTION_EDIT , ACTION_MAIN , etc. data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri .