Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
UNIR – UNIVERSIDAD INTERNACIONAL DE LA RIOJA
MÁSTER UNIVERSITARIO EN INGENIERÍA DE SOFTWARE Y SISTEMAS INFORMÁTICOS
PLATAFORMAS DE DESARROLLO DE SOFTWARE
ACTIVIDAD: Práctica #2: Desarrollo de aplicaciones en Android
PRESENTADO POR: Jorge Henry Cuenca Bejar
Contenido:
1. Instalación de Android Studio …………………………………………………… 2. Aplicación en Android Studio ……………………………………………………. 2.1. Pantallas de Aplicación Android Studio ………………………………. 2.2. Pantallas de Advertencia ……………………………………………………. 2.3. Pantallas de Diseño de App ………………………………………………… 3. Funcionamiento de App en Equipo Físico …………………………………. 4. Detalle de código ………………………………………………………………………. 4.1. Código para validar campos ……………………………………………….. 4.2. Código para borrar formulario ……………………………………………. 4.3. Código Fuente PedidoActivity.java y Activity_pedido.xml …… 4.4. Código Fuente ConfirmacionActivity.java y Activity_Confirmacion.xml ……………………………………………………
TEMA 9 – Actividades
-0-
1 6 6 12 16 18 19 19 20 21 26
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
1. INSTALACIÓN DE ANDROID STUDIO: Para instalar Android Studio se debe seguir los siguientes pasos: Ingresar a la página de Android Studio y descargar el instalador. La página es https://developer.android.com/studio/?hl=es-419.. https://developer.android.com/studio/?hl=es-419
Seleccionar la opción correcta, de acuerdo al sistema operativo.
Una vez descargado el archivo, iniciar el instalador.
TEMA 9 – Actividades
-1-
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Se abrirá el asistente para la instalación. Dar siguiente:
Dar siguiente.
TEMA 9 – Actividades
-2-
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Seleccionar los componentes que se desean instalar. En este caso es necesario instalar Android Virtual Device.
Seleccionamos la carpeta donde se instalará el programa.
TEMA 9 – Actividades
-3-
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Presionamos el botón Install.
Se muestra el progreso de la instalación.
TEMA 9 – Actividades
-4-
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Una vez finalizada la instalación, presionar Next.
Finalizamos la instalación y abrimos Android Studio.
TEMA 9 – Actividades
-5-
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
2. APLICACIÓN EN ANDROID STUDIO: 2.1. Pantallas de Aplicación en Android Studio: Pantalla principal: cuando se ingresa al aplicativo se muestra los campos y el usuario llena los valores.
TEMA 9 – Actividades
-6-
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
TEMA 9 – Actividades
-7-
Fecha
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Acción al presionar el botón “Enviar Pedido”: se muestra una ventana para que el usuario confirme el pedido. Si presiona “Cancelar” se regresa a la ventana anterior. Si se presiona “Enviar” se confirma el pedido con un mensaje.
TEMA 9 – Actividades
-8-
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
TEMA 9 – Actividades
-9-
Fecha
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Acción al presionar el botón “Enviar”: se confirma el pedido con un mensaje.
TEMA 9 – Actividades
- 10 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
TEMA 9 – Actividades
- 11 -
Fecha
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
2.2. Pantallas de Advertencia: Si el usuario no ingresa los valores solicitado, se muestra un mensaje de advertencia.
TEMA 9 – Actividades
- 12 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
TEMA 9 – Actividades
- 13 -
Fecha
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Se ha configurado el campo “Cantidad Requerida” para que sólo acepte números positivos mayores a cero.
TEMA 9 – Actividades
- 14 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Para probar el aplicativo, se ha usado el equipo virtual Nexus 5X.
TEMA 9 – Actividades
- 15 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
2.3. Pantallas de Diseño de App: Pantalla de Pedido
TEMA 9 – Actividades
- 16 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
Pantalla de Confirmación
TEMA 9 – Actividades
- 17 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
3. Funcionamiento de App en Equipo Físico: El App desarrollada se ha probado en un equipo físico de la Marca Samsung Galaxy. Se adjunta las pantallas.
TEMA 9 – Actividades
- 18 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
4. Detalle código: 4.1. Código para validar campos: Se realiza las siguientes validaciones: -
Nombre medicamento: que se haya llenado el campo.
-
Tipo de medicamento: que se seleccione una opción.
-
Cantidad requerida: que se haya llenado el campo, con un número y que sea mayor a cero (la cantidad no puede ser cero o negativo).
-
Proveedor: que se haya seleccionado un proveedor.
-
Sucursal receptora: que se seleccione al menos una sucursal.
Después de validar la información, se envía al formulario de confirmación. El código es el siguiente (copiado desde Android Studio):
1. //metodo para enviar formulario 2. fnEnviar(View view){ public void 3. //borrar datos 4. etNombreMedicamento = (EditText )findViewById (R.id.txtNombreMedicamento ); 5. etCantidad = (EditText )findViewById (R.id.txtCantidadRequerida ); 6. spTipoMedimanteo = (Spinner)findViewById (R.id.cboTipoMedicamento ); 7. rbCofarma = (RadioButton )findViewById (R.id.rbuCofarma ); 8. rbEmpseoha = (RadioButton )findViewById (R.id.rbuEmpsepha ); 9. rbComefar = (RadioButton )findViewById (R.id.rbuCemefar ); 10. chPrincipal = (CheckBox )findViewById (R.id.chkFarmaciaPrincipal ); 11. chSecundaria = (CheckBox )findViewById (R.id.chkFarmaciaSecundaria ); 12. 13. strError = ""; 14. strError += (!etNombreMedicamento. getText().toString ().trim().isEmpty()) ? "" : "Ingrese el nombre del medicamento. \n"; 15. strError += (spTipoMedimanteo. getSelectedItem ().toString ().equals("--Seleccione Tipo---" )) ? "Seleccione el tipo de medicamento. \n" : ""; 16. strError += (!etCantidad. getText().toString ().trim().isEmpty()) ? "" : "Ingres e la cantidad. \n"; 17. strError += (!rbCofarma. isChecked () && !rbEmpseoha. isChecked () && !rbComefar. i sChecked ()) ? "Debe seleccionar un distribuidor. \n" : ""; 18. strError += !chPrincipal. isChecked () && !chSecundaria. isChecked () ? "Debe seleccionar al menos una sucursal receptora. \n" : ""; 19. 20. //si hay error => mostrar mensaje 21. if(!strError. isEmpty()) 22. { 23. //mostrar mensaje de advertencia 24. AlertDialog. Builder builder = new AlertDialog.Builder(this ); 25. builder. setMessage (strError ); 26. builder. setTitle ("Advertencia" ); 27. builder. setPositiveButton ("Aceptar" , new DialogInterface. OnClickListener () { 28. @Override 29. onClick(DialogInterface dialog, int which) { public void 30. dialog.cancel(); 31. } 32. }); 33. 34. AlertDialog dialogoAdvertencia = builder.create(); 35. dialogoAdvertencia. show(); 36.
TEMA 9 – Actividades
- 19 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
37. 38. 39. 40. 41. 42. 43. 44.
Fecha
return ;
} //enviar datos al otro formulario String strFarmaPrincipal = "Calle de la Rosa Nro. 28 (Farmacia Principal)" ; String strFarmaSecundaria = "Calle Alcazabilla Nro. 3 (Farmacia Segundaria)" ; String strMedicamentoMensaje = etCantidad.getText().toString ().trim() + " del " + spTipoMedimanteo. getSelectedItem ().toString () + " " + etNombreMedicamento. getText().toString ().trim();
45. 46. 47. 48.
String strDireccion = ""; strDireccion += chPrincipal.isChecked () ? strFarmaPrincipal : ""; strDireccion += chSecundaria. isChecked () ? (strDireccion. isEmpty() ? strFarmaS ecundaria : " y para la situada en " + strFarmaSecundaria ) : ""; 49. strDireccion = "Para la farmacia situada en " + strDireccion ; 50. 51. String strDistribuidor = ""; 52. strDistribuidor = rbCofarma.isChecked () ? rbCofarma.getText().toString () : str Distribuidor ; 53. strDistribuidor = rbEmpseoha. isChecked () ? rbEmpseoha. getText().toString () : s trDistribuidor ; 54. strDistribuidor = rbComefar.isChecked () ? rbComefar.getText().toString () : str Distribuidor ; 55. strDistribuidor = "Pedido al distribuidor \n" + strDistribuidor ; 56. 57. //crear un Intent para enviar información 58. Intent intentConfirmacion = new Intent(this , ConfirmacionActivity. class); 59. 60. //enviar la informacion con putExtra 61. intentConfirmacion. putExtra ("Medicamento" , strMedicamentoMensaje ); 62. intentConfirmacion. putExtra ("Direccion" , strDireccion ); 63. intentConfirmacion. putExtra ("Distribuidor" , strDistribuidor ); 64. 65. startActivity (intentConfirmacion ); 66. }
4.2. Código para Borrar Formulario: El código para borrar o limpiar el formulario es el siguiente (Copiado desde Android Studio):
1. //metodo para borrar formulario 2. metodoBorrar(View view){ public void 3. //borrar datos 4. etNombreMedicamento = (EditText )findViewById (R.id.txtNombreMedicamento ); 5. etCantidad = (EditText )findViewById (R.id.txtCantidadRequerida ); 6. spTipoMedimanteo = (Spinner)findViewById (R.id.cboTipoMedicamento ); 7. rbCofarma = (RadioButton )findViewById (R.id.rbuCofarma ); 8. rbEmpseoha = (RadioButton )findViewById (R.id.rbuEmpsepha ); 9. rbComefar = (RadioButton )findViewById (R.id.rbuCemefar ); 10. chPrincipal = (CheckBox )findViewById (R.id.chkFarmaciaPrincipal ); 11. chSecundaria = (CheckBox )findViewById (R.id.chkFarmaciaSecundaria ); 12. 13. etNombreMedicamento. setText(""); 14. etCantidad. setText(""); 15. spTipoMedimanteo. setSelection (0); 16. rbCofarma. setChecked (false); 17. rbEmpseoha. setChecked (false ); 18. rbComefar. setChecked (false); 19. chPrincipal. setChecked (false); 20. chSecundaria. setChecked (false ); 21. }
TEMA 9 – Actividades
- 20 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
4.3. Código Fuente Pedido.java y Activity_pedido.xml Pedido.java 1. package com.jorgecuenca.farmacia ; 2. 3. import android.content.DialogInterface ; 4. import android.content.Intent ; 5. import android.hardware.display.DisplayManager ; 6. import android.support.v7.app.AlertDialog ; 7. import android.support.v7.app.AppCompatActivity ; 8. import android.os.Bundle ; 9. import android.view.View ; 10. import android.widget.ArrayAdapter ; 11. import android.widget.Button ; 12. import android.widget.CheckBox ; 13. import android.widget.EditText ; 14. import android.widget.RadioButton ; 15. import android.widget.Spinner ; 16. import android.widget.TextView ; 17. 18. import javax.xml.transform.stream.StreamResult ; 19. 20. public class Pedido extends AppCompatActivity { 21. 22. //crear una varibale para almacenar los datos del combobox Tipo Medicamento 23. Spinner opciones ; 24. 25. //public final static String EXTRA_MESSAGE = "com.jorgecuenca.MESSAGE"; 26. 27. //variables para obtener los datos del formulario 28. EditText etNombreMedicamento, etCantidad ; 29. Spinner spTipoMedimanteo ; 30. RadioButton rbCofarma, rbEmpseoha, rbComefar ; 31. CheckBox chPrincipal, chSecundaria ; 32. 33. //variable para obttener error 34. public static String strError ; 35. 36. @Override 37. onCreate(Bundle savedInstanceState ) { protected void 38. super .onCreate (savedInstanceState ); 39. setContentView (R.layout.activity_pedido ); 40. 41. //recuperar el ComboBox 42. opciones = (Spinner)findViewById (R.id.cboTipoMedicamento ); 43. 44. //Recuperar los datos de Tipo Medicamento en un ArrayAdapter 45. ArrayAdapter
adapter = ArrayAdapter. createFromResource (this , R.array.opcionesTipoMedicamento , android.R.layout.simple_spinner_item ); 46. //Agregar los elementos del adapter al ComboBox 47. opciones. setAdapter (adapter); 48. } 49. 50. 51. //metodo para borrar formulario 52. metodoBorrar(View view){ public void 53. //borrar datos 54. etNombreMedicamento = (EditText )findViewById (R.id.txtNombreMedicamento ); 55. etCantidad = (EditText )findViewById (R.id.txtCantidadRequerida ); 56. spTipoMedimanteo = (Spinner)findViewById (R.id.cboTipoMedicamento ); 57. rbCofarma = (RadioButton )findViewById (R.id.rbuCofarma ); 58. rbEmpseoha = (RadioButton )findViewById (R.id.rbuEmpsepha ); 59. rbComefar = (RadioButton )findViewById (R.id.rbuCemefar ); 60. chPrincipal = (CheckBox )findViewById (R.id.chkFarmaciaPrincipal ); 61. chSecundaria = (CheckBox )findViewById (R.id.chkFarmaciaSecundaria ); 62. 63. etNombreMedicamento. setText(""); 64. etCantidad. setText("");
TEMA 9 – Actividades
- 21 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99.
Fecha
spTipoMedimanteo. setSelection (0); rbCofarma. setChecked (false); rbEmpseoha. setChecked (false ); rbComefar. setChecked (false); chPrincipal. setChecked (false); chSecundaria. setChecked (false ); } //metodo para enviar formulario fnEnviar(View view){ public void //borrar datos etNombreMedicamento = (EditText )findViewById (R.id.txtNombreMedicamento ); etCantidad = (EditText )findViewById (R.id.txtCantidadRequerida ); spTipoMedimanteo = (Spinner)findViewById (R.id.cboTipoMedicamento ); rbCofarma = (RadioButton )findViewById (R.id.rbuCofarma ); rbEmpseoha = (RadioButton )findViewById (R.id.rbuEmpsepha ); rbComefar = (RadioButton )findViewById (R.id.rbuCemefar ); chPrincipal = (CheckBox )findViewById (R.id.chkFarmaciaPrincipal ); chSecundaria = (CheckBox )findViewById (R.id.chkFarmaciaSecundaria ); strError = ""; strError += (!etNombreMedicamento. getText().toString ().trim().isEmpty()) ? "" : "Ingrese el nombre del medicamento. \n"; strError += (spTipoMedimanteo. getSelectedItem ().toString ().equals("--Seleccione Tipo---" )) ? "Seleccione el tipo de medicamento. \n" : ""; strError += (!etCantidad. getText().toString ().trim().isEmpty()) ? "" : "Ingres e la cantidad. \n"; strError += (!rbCofarma. isChecked () && !rbEmpseoha. isChecked () && !rbComefar. i sChecked ()) ? "Debe seleccionar un distribuidor. \n" : ""; strError += !chPrincipal. isChecked () && !chSecundaria. isChecked () ? "Debe seleccionar al menos una sucursal receptora. \n" : ""; //si hay error => mostrar mensaje if(!strError. isEmpty()) { //mostrar mensaje de advertencia AlertDialog. Builder builder = new AlertDialog.Builder(this ); builder. setMessage (strError ); builder. setTitle ("Advertencia" ); builder. setPositiveButton ("Aceptar" , new DialogInterface. OnClickListener ()
{ 100. @Override 101. onClick(DialogInterface dialog, int which) { public void 102. dialog.cancel(); 103. } 104. }); 105. 106. AlertDialog dialogoAdvertencia = builder.create(); 107. dialogoAdvertencia. show(); 108. 109. return ; 110. } 111. 112. //enviar datos al otro formulario 113. String strFarmaPrincipal = "Calle de la Rosa Nro. 28 (Farmacia Principal)" ; 114. String strFarmaSecundaria = "Calle Alcazabilla Nro. 3 (Farmacia Segundaria)" ; 115. 116. String strMedicamentoMensaje = etCantidad.getText().toString ().trim() + " del " + spTipoMedimanteo. getSelectedItem ().toString () + " " + etNombreMedicamento. getText().toString ().trim(); 117. 118. String strDireccion = ""; 119. strDireccion += chPrincipal. isChecked () ? strFarmaPrincipal : ""; 120. strDireccion += chSecundaria. isChecked () ? (strDireccion. isEmpty() ? st rFarmaSecundaria : " y para la situada en " + strFarmaSecundaria ) : ""; 121. strDireccion = "Para la farmacia situada en " + strDireccion ; 122. 123. String strDistribuidor = ""; 124. strDistribuidor = rbCofarma.isChecked () ? rbCofarma.getText().toString ( ) : strDistribuidor ;
TEMA 9 – Actividades
- 22 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
Fecha
125. strDistribuidor = rbEmpseoha.isChecked () ? rbEmpseoha.getText().toStrin g() : strDistribuidor ; 126. strDistribuidor = rbComefar.isChecked () ? rbComefar.getText().toString ( ) : strDistribuidor ; 127. strDistribuidor = "Pedido al distribuidor \n" + strDistribuidor ; 128. 129. //crear un Intent para enviar información 130. Intent intentConfirmacion = new Intent(this, ConfirmacionActivity. class ); 131. 132. //enviar la informacion con putExtra 133. intentConfirmacion. putExtra("Medicamento" , strMedicamentoMensaje ); 134. intentConfirmacion. putExtra("Direccion" , strDireccion ); 135. intentConfirmacion. putExtra("Distribuidor" , strDistribuidor ); 136. 137. startActivity (intentConfirmacion ); 138. } 139. }
Activity_pedido.xml 1. 2. 8. 9. 23. 24. 35. 36.
TEMA 9 – Actividades
- 23 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120.
Fecha
android:text ="" app:layout_constraintEnd_toEndOf ="parent" app:layout_constraintStart_toStartOf ="parent" app:layout_constraintTop_toBottomOf ="@+id/lblNombreMedicamento"
/>
/>
/>
/>
/>
/>
TEMA 9 – Actividades
- 24 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193.
Fecha
android:layout_height ="wrap_content" android:layout_marginStart ="16dp" android:layout_marginLeft ="16dp" android:layout_marginTop ="7dp" android:orientation ="vertical" app:layout_constraintStart_toStartOf ="parent" app:layout_constraintTop_toBottomOf ="@+id/lblDistribuidor" >
TEMA 9 – Actividades
- 25 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226.
Fecha
android:layout_marginStart ="16dp" android:layout_marginLeft ="16dp" android:layout_marginTop ="6dp" android:layout_marginEnd ="16dp" android:layout_marginRight ="16dp" android:orientation ="horizontal" app:layout_constraintEnd_toEndOf ="parent" app:layout_constraintStart_toStartOf ="parent" app:layout_constraintTop_toBottomOf ="@+id/contenedorCheckBox" >
4.4. Código Fuente ConfirmacionActivity.java y Activity_Confirmacion.xml ConfirmacionActivity.java 1. package com.jorgecuenca.farmacia ; 2. 3. import android.content.Intent ; 4. import android.support.v7.app.AppCompatActivity ; 5. import android.os.Bundle ; 6. import android.view.View ; 7. import android.widget.EditText ; 8. import android.widget.TextView ; 9. import android.widget.Toast ; 10. 11. public class ConfirmacionActivity extends AppCompatActivity { 12. 13. //variables para obtener campos de formulario 14. TextView tvDistribuidor, tvNombreMedicamento, tvDireccionEnvio ; 15. 16. @Override 17. onCreate(Bundle savedInstanceState ) { protected void 18. super .onCreate (savedInstanceState ); 19. setContentView (R.layout.activity_confirmacion ); 20. 21. //obtener datos 22. tvDistribuidor = (TextView) findViewById (R.id.txtPedidoDistribuidor ); 23. tvNombreMedicamento = (TextView ) findViewById(R.id.txtMedicamentoSolicitado ); 24. tvDireccionEnvio = (TextView ) findViewById(R.id.txtDireccionEnvio ); 25. 26. //crear Bundle para recibir los datos del otro formulario 27. Bundle bundlePedido = getIntent().getExtras (); 28. 29. tvDistribuidor. setText(bundlePedido. getString ("Distribuidor" ));
TEMA 9 – Actividades
- 26 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42.
Fecha
tvNombreMedicamento. setText(bundlePedido. getString ("Medicamento" )); tvDireccionEnvio. setText(bundlePedido. getString ("Direccion" )); } //funcion para cancelar y volver al formulario anterior fnCancelar(View view) { public void this.finish(); }
//funcion para confirmar fnConfirmar (View view) { public void //mostrar mensaje de envío y cerrar Toast.makeText (this , "Pedido enviado correctamente." , Toast.LENGTH_LONG ).show(); 43. this.finish(); 44. 45. //Intent intentPedido = new Intent(this, Pedido.class); 46. //startActivity(intentPedido); 47. 48. } 49. }
Activity_Confirmacion.xml 1. 2. 8. 9. 18. 19. 30. 31. 42. 43.
TEMA 9 – Actividades
- 27 -
© Universidad Internacional de La Rioja (UNIR)
Asignatura
Datos del alumno
Plataformas de Desarrollo de
Apellidos: CUENCA BEJAR
Software
Nombre: JORGE CUENCA
45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112.
Fecha
android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_marginStart ="16dp" android:layout_marginLeft ="16dp" android:layout_marginTop ="7dp" android:text ="Medicamento Solicitado" app:layout_constraintStart_toStartOf ="parent" app:layout_constraintTop_toBottomOf ="@+id/lblMedicamentoSolicitado"
/>
/>
/>
TEMA 9 – Actividades
- 28 -
© Universidad Internacional de La Rioja (UNIR)