Android Open Source - SQLite Actual Per






From Project

Back to project page SQLite.

License

The source code is released under:

GNU General Public License

If you think the Android project SQLite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bugsoft.erwin.sqlite1;
/*  w  w  w  . j  a v  a  2  s.c o  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import com.bugsoft.erwin.sqlite1.BD.ConPers;
import com.bugsoft.erwin.sqlite1.BD.PersonaGetSet;

/**
 * Created by erwin on 22/11/14.
 */
public class ActualPer extends Activity{

    EditText nomb, appat, apmat, edad, cel, dir;
    RadioButton masc, fem;
    CheckBox car;
    ConPers miBase;

    String idActual;
    String sexo, carro;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.persona);

        nomb = (EditText)findViewById(R.id.editText);
        appat = (EditText)findViewById(R.id.editText2);
        apmat = (EditText)findViewById(R.id.editText3);
        edad = (EditText)findViewById(R.id.editText4);
        cel = (EditText)findViewById(R.id.editText5);
        dir = (EditText)findViewById(R.id.editText6);
        masc = (RadioButton)findViewById(R.id.radioButton);
        fem = (RadioButton)findViewById(R.id.radioButton2);
        car = (CheckBox)findViewById(R.id.checkBox);

        miBase = new ConPers(this);

        Bundle idper =  getIntent().getExtras();
        idActual = idper.getString("id");

        PersonaGetSet pPersona = miBase.PerActual(idActual);

        nomb.setText(pPersona.getNombre());
        appat.setText(pPersona.getAppat());
        apmat.setText(pPersona.getApmat());
        edad.setText(String.valueOf(pPersona.getEdad()));
        cel.setText(pPersona.getCel());
        dir.setText(pPersona.getDirec());

        if(pPersona.getSexo().equals("Masculino")){
            masc.setChecked(true);
        } else{
            fem.setChecked(true);
        }

        if(pPersona.getCarro().equals("true")){
            car.setChecked(true);
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        final int id = item.getItemId();

        if (id == R.id.actualiza) {

            String nombre = nomb.getText().toString().trim();
            String app = appat.getText().toString().trim();
            String apm = apmat.getText().toString().trim();
            String age =edad.getText().toString().trim();
            String cell = cel.getText().toString().trim();
            String direc = dir.getText().toString().trim();

            if(nombre.equals("") || app.equals("") || apm.equals("") || age.equals("") || cell.equals("") || direc.equals("")){
                Toast.makeText(ActualPer.this, "Falta llenar uno o varios campos", Toast.LENGTH_SHORT).show();
            }else {

                int edadp = Integer.valueOf(age);
                if(masc.isChecked()){
                    sexo = masc.getText().toString();
                }else {
                    sexo = fem.getText().toString();
                }

                if(car.isChecked()){
                    carro = "true";
                }else {
                    carro = "false";
                }

                PersonaGetSet persona = new PersonaGetSet();
                persona.setNombre(nombre);
                persona.setAppat(app);
                persona.setApmat(apm);
                persona.setEdad(edadp);
                persona.setCel(cell);
                persona.setDirec(direc);
                persona.setSexo(sexo);
                persona.setCarro(carro);
                persona.setId(idActual);

                int res = miBase.Actualizar(persona);
                if(res>0){
                    Toast.makeText(ActualPer.this,"Persona actualizada",Toast.LENGTH_SHORT).show();
                    finish();
                }else {
                    Toast.makeText(ActualPer.this,"Error al actualizar",Toast.LENGTH_SHORT).show();
                }
            }

            return true;
        }

        if (id == R.id.elimina){
            AlertDialog.Builder dialogo = new AlertDialog.Builder(this);
            dialogo.setIcon(R.drawable.ic_launcher);
            dialogo.setTitle("Elimina persona");
            dialogo.setMessage("Estas seguro de elimina a esta persona?");
            dialogo.setPositiveButton("Aceptar",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int resultado = miBase.Elimina(idActual);

                    if(resultado>0){
                        Toast.makeText(ActualPer.this,"Persona eliminada",Toast.LENGTH_SHORT).show();
                        finish();
                    }else {
                        Toast.makeText(ActualPer.this,"Error al eliminar",Toast.LENGTH_SHORT).show();
                    }

                }
            });

            dialogo.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {}
            });

            dialogo.show();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}




Java Source Code List

com.bugsoft.erwin.sqlite1.ActualPer.java
com.bugsoft.erwin.sqlite1.ApplicationTest.java
com.bugsoft.erwin.sqlite1.Busquedas.java
com.bugsoft.erwin.sqlite1.MainActivity.java
com.bugsoft.erwin.sqlite1.BD.ConPers.java
com.bugsoft.erwin.sqlite1.BD.PersonaGetSet.java