Back to project page SQLite.
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.
package com.bugsoft.erwin.sqlite1; /*www . j a v a 2s.co m*/ import android.app.Activity; import android.content.Intent; 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; public class MainActivity extends Activity { EditText nomb, appat, apmat, edad, cel, dir; RadioButton masc, fem; CheckBox car; ConPers miBase; String nombre, app, apm, age, cell, direc, sexo, carro; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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); } private void limpiar(){ nomb.setText(""); appat.setText(""); apmat.setText(""); edad.setText(""); cel.setText(""); dir.setText(""); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.agregar) { nombre = nomb.getText().toString().trim(); app = appat.getText().toString().trim(); apm = apmat.getText().toString().trim(); age =edad.getText().toString().trim(); cell = cel.getText().toString().trim(); direc = dir.getText().toString().trim(); if(nombre.equals("") || app.equals("") || apm.equals("") || age.equals("") || cell.equals("") || direc.equals("")){ Toast.makeText(MainActivity.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); long res = miBase.insertar(persona); if(res>0){ Toast.makeText(MainActivity.this,"Persona Agregada",Toast.LENGTH_SHORT).show(); this.limpiar(); }else { Toast.makeText(MainActivity.this,"Error al agregar",Toast.LENGTH_SHORT).show(); this.limpiar(); } } return true; }else if (id == R.id.buscar) { Intent dos = new Intent("com.bugsoft.erwin.sqlite1.intent.Busquedas"); startActivity(dos); return true; } return super.onOptionsItemSelected(item); } }