I use two EditText ( et_miembro_id
) and ( et_fecha_id
), but what I write in et_miembro_id
is what is also added in et_fecha_id
.
What I do not want is for the same text to appear in both, I want them to go separately, that is
-
et_miembro_id
for names. -
et_fecha_id
to write a date,
but what I write in member is added only on date.
Example:
AddPersona.java
public class AgregarPersona extends Activity implements OnClickListener {
EditText et;
EditText et2;
Button btnAgregar, read_bt;
SQLControlador dbconeccion;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.agregar_persona);
et = (EditText) findViewById(R.id.et_nombre_id);
et2 = (EditText) findViewById(R.id.et_fecha_id);
btnAgregar = (Button) findViewById(R.id.btnAgregarId);
dbconeccion = new SQLControlador(this);
dbconeccion.abrirBaseDeDatos();
btnAgregar.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btnAgregarId:
String name = et.getText().toString();
dbconeccion.insertarDatos(name);
Intent main = new Intent(AgregarPersona.this, MyActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(main);
break;
default:
break;
}
}
}
SQLControlador.java
public class SQLControlador {
private DBhelper dbhelper;
private Context ourcontext;
private SQLiteDatabase database;
public SQLControlador(Context c) {
ourcontext = c;
}
public SQLControlador abrirBaseDeDatos() throws SQLException {
dbhelper = new DBhelper(ourcontext);
database = dbhelper.getWritableDatabase();
return this;
}
public void cerrar() {
dbhelper.close();
}
public void insertarDatos(String name) {
ContentValues cv = new ContentValues();
cv.put(DBhelper.PERSONA_NOMBRE, name);
cv.put(DBhelper.PERSONA_FECHA, name);
database.insert(DBhelper.TABLE_MEMBER, null, cv);
}
public Cursor leerDatos() {
String[] todasLasColumnas = new String[] {
DBhelper.PERSONA_ID,
DBhelper.PERSONA_NOMBRE,
DBhelper.PERSONA_FECHA
};
Cursor c = database.query(DBhelper.TABLE_MEMBER, todasLasColumnas, null,
null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
public int actualizarDatos(long memberID, String memberName, String memberFecha) {
ContentValues cvActualizar = new ContentValues();
cvActualizar.put(DBhelper.PERSONA_NOMBRE, memberName);
cvActualizar.put(DBhelper.PERSONA_FECHA, memberFecha);
int i = database.update(DBhelper.TABLE_MEMBER, cvActualizar,
DBhelper.PERSONA_ID + " = " + memberID, null);
return i;
}
public void deleteData(long memberID) {
database.delete(DBhelper.TABLE_MEMBER, DBhelper.PERSONA_ID + "="
+ memberID, null);
}
}