Documentacion

5

Click here to load reader

Transcript of Documentacion

Page 1: Documentacion

UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS

TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN

Materia

Desarrollo de aplicaciones III

Tema

Aplicación android

Nombre completo del Alumno:

Héctor Daniel Hernández zapata

Grado: 5 Grupo: “A”

Nombre del Docente:eloy

Fecha de entrega : 24/03/2014

Page 2: Documentacion

UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS

TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN

Este codigo es sobre una aplicación donde guarda, elimina, modifica y consulta datos sobre un alumno. Comenzamos asiendo la clase MainActivity en esta clase es donde empezamos a diseñar la interfaz en este caso vamos a agregar 4 botones, 4 textfields y 4 editText. importandroid.app.Activity; importandroid.content.ContentValues; importandroid.database.Cursor; importandroid.database.sqlite.SQLiteDatabase; importandroid.os.Bundle; importandroid.view.Menu; importandroid.view.View; importandroid.widget.EditText; importandroid.widget.Toast; publicclassMainActivityextends Activity { privateEditTextet1, et2, et3, et4; @Override protectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et1 = (EditText) findViewById(R.id.editText1); et2 = (EditText) findViewById(R.id.editText2); et3 = (EditText) findViewById(R.id.editText3); et4 = (EditText) findViewById(R.id.editText4); } @Override publicbooleanonCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); returntrue; } Este código sirve para guardar los datos que se van registrando en la interfaz.

Page 3: Documentacion

UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS

TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN

publicvoidguardar(View v) { AdminSQLiteOpenHelper admin = newAdminSQLiteOpenHelper(this, "administracion", null, 1); SQLiteDatabasebd = admin.getWritableDatabase(); String dni = et1.getText().toString(); String nombre = et2.getText().toString(); String colegio = et3.getText().toString(); String nromesa = et4.getText().toString(); ContentValuesregistro = newContentValues(); registro.put("dni", dni); registro.put("clave", nombre); registro.put("apodo", colegio); registro.put("escuela", nromesa); bd.insert("votantes", null, registro); bd.close(); et1.setText(""); et2.setText(""); et3.setText(""); et4.setText(""); Toast.makeText(this, "Se cargaron los datos de la persona", Toast.LENGTH_SHORT).show(); } Este código sirve para consultar los datos que se van registrando en la interfaz. publicvoidconsulta(View v) { AdminSQLiteOpenHelper admin = newAdminSQLiteOpenHelper(this, "administracion", null, 1); SQLiteDatabasebd = admin.getWritableDatabase(); String dni = et1.getText().toString(); Cursor fila = bd.rawQuery( "selectclave,apodo,escuelafrom votantes wheredni=" + dni + "", null); if (fila.moveToFirst()) { et2.setText(fila.getString(0)); et3.setText(fila.getString(1)); et4.setText(fila.getString(2)); } else Toast.makeText(this, "No existe una persona con dicho dni", Toast.LENGTH_SHORT).show(); bd.close(); } Este código sirve para eliminar los datos que se van registrando en la interfaz.

Page 4: Documentacion

UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS

TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN

publicvoideliminar(View v) { AdminSQLiteOpenHelper admin = newAdminSQLiteOpenHelper(this, "administracion", null, 1); SQLiteDatabasebd = admin.getWritableDatabase(); String dni = et1.getText().toString(); intcant = bd.delete("votantes", "dni=" + dni + "", null); bd.close(); et1.setText(""); et2.setText(""); et3.setText(""); et4.setText(""); if (cant == 1) Toast.makeText(this, "Se borró la persona con dichodocumento", Toast.LENGTH_SHORT).show(); else Toast.makeText(this, "No existe una persona con dicho documento", Toast.LENGTH_SHORT).show(); } Este código sirve para modificar los datos que se van registrando en la interfaz. publicvoidmodificar(View v) { AdminSQLiteOpenHelper admin = newAdminSQLiteOpenHelper(this, "administracion", null, 1); SQLiteDatabasebd = admin.getWritableDatabase(); String dni = et1.getText().toString(); String nombre = et2.getText().toString(); String colegio = et3.getText().toString(); String nromesa = et4.getText().toString(); ContentValuesregistro = newContentValues(); registro.put("clave", nombre); registro.put("apodo", colegio); registro.put("escuela", nromesa); intcant = bd.update("votantes", registro, "dni=" + dni, null); bd.close(); if (cant == 1) Toast.makeText(this, "se modificaron los datos", Toast.LENGTH_SHORT) .show(); else Toast.makeText(this, "no existe una persona con dicho documento", Toast.LENGTH_SHORT).show(); } }

Page 5: Documentacion

UNIVERSIDAD TECNONOLÓGICA DEL ESTADO DE ZACATECAS UNIDAD ACADÉMICA DE PINOS

TECNOLOGÍAS DE LA INFORMACIÓN Y COMUNICACIÓN

Esta clase muestra el código de la base de datos aquí se va a ir guardando todos los alumnos que

se van registrando.

@Override

Public void onUpgrade(SQLiteDatabasedb, intversionAnte, intversionNue) {

db.execSQL("drop table if exists votantes");

db.execSQL("createtable votantes(dniintegerprimarykey, clave text, apodo text,

escuela integer)");

}

Aquí se muestra los resultados de cuando ya esta ejecutada la aplicación android.