First question I ask in stackoverflow because I'm confused, I try to change a data in SQLite from a custom ListView and it turns out that all the data is changed and I just want to change the one of the selected item. I try to change just one data in SQLite but for some reason they all change.
GetView code in the getView of the adapter I have two buttons and one of those I want you to modify a data in SQLite that changes the balance '
@Override
public View getView(final int position, View view, ViewGroup viewGroup) {
View vista = view;
LayoutInflater inflater = LayoutInflater.from(context);
vista=inflater.inflate(R.layout.item_cliente,null);
TextView lblnombre = (TextView) vista.findViewById(R.id.lblnombre);
final EditText lblabono = (EditText) vista.findViewById(R.id.txtabonoitem);
TextView lblletrasatraso = (TextView) vista.findViewById(R.id.lblletrasatrasoitem);
TextView lblcotasdeatraso = (TextView) vista.findViewById(R.id.lblcotasdeatrasoitem);
TextView lblcotaspendientes = (TextView) vista.findViewById(R.id.lblcotaspendientesitem);
lblsaldo = (TextView) vista.findViewById(R.id.lblsaldoitem);
TextView lblcota = (TextView) vista.findViewById(R.id.lblcotadiriaitem);
TextView lblplazo = (TextView) vista.findViewById(R.id.lblplazoitem);
final ProgressBar progresoplata = (ProgressBar) vista.findViewById(R.id.progresobar);
final ProgressBar progresodia = (ProgressBar) vista.findViewById(R.id.progresobardia);
final ProgressBar progreoscargando = (ProgressBar) vista.findViewById(R.id.progresocargando);
TextView lbldiaprestado = (TextView) vista.findViewById(R.id.lbldiaprestadoitem);
TextView lblmodalidad = (TextView) vista.findViewById(R.id.lblmodalidaditem);
TextView lblcedula = (TextView) vista.findViewById(R.id.lblcedulaitem);
TextView lblcobrador = (TextView) vista.findViewById(R.id.lblcobradoritem);
final TextView lblcodigo = (TextView) vista.findViewById(R.id.lblcodigoitem);
final TextView lbltelefono = (TextView) vista.findViewById(R.id.lbltelefonoitem);
TextView lbldireccion = (TextView) vista.findViewById(R.id.lblobservacionitem);
final TextView lblobservacion = (TextView) vista.findViewById(R.id.lblobservacionitem);
Button pagar = (Button) vista.findViewById(R.id.btnpagaritem);
Button llamar = (Button) vista.findViewById(R.id.btnllamaritem);
lblnombre.setText(ListaObejtos.get(position).getNombre().toString());
lblabono.setText(ListaObejtos.get(position).getAbono().toString());
lblletrasatraso.setText(ListaObejtos.get(position).getLetrasatraso().toString());
lblcotasdeatraso.setText(ListaObejtos.get(position).getAtraso().toString());
lblcotaspendientes.setText(ListaObejtos.get(position).getAtraso().toString());
lblsaldo.setText(ListaObejtos.get(position).getSaldo().toString());
lblcota.setText(ListaObejtos.get(position).getCota().toString());
lblplazo.setText(ListaObejtos.get(position).getPlazo().toString());
progresoplata.setProgress(Integer.parseInt(ListaObejtos.get(position).getProgreosdinero().toString()));
progresodia.setProgress(Integer.parseInt(ListaObejtos.get(position).getProgresodia().toString()));
lbldiaprestado.setText(ListaObejtos.get(position).getDiaPrestado().toString());
lblmodalidad.setText(ListaObejtos.get(position).getModalidad().toString());
lblcedula.setText(ListaObejtos.get(position).getCedula().toString());
lblcobrador.setText(ListaObejtos.get(position).getCobrador().toString());
lblcodigo.setText(ListaObejtos.get(position).getCodigo().toString());
lbltelefono.setText(ListaObejtos.get(position).getTelefono().toString());
lbldireccion.setText(ListaObejtos.get(position).getDireccion().toString());
lblobservacion.setText(ListaObejtos.get(position).getObservacion().toString());
progreoscargando.setIndeterminate(false);
pagar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int abn = Integer.parseInt(ListaObejtos.get(position).getAbono().toString());
int sal = Integer.parseInt(ListaObejtos.get(position).getSaldo().toString());
int abono = Integer.parseInt(lblabono.getText().toString());
int saldo = Integer.parseInt(lblsaldo.getText().toString());
String codigo = ListaObejtos.get(position).getCodigo().toString();
String observacion = lblobservacion.getText().toString();
final int resultado = saldo-abono;
mensajeToast("Abono "+abono);
lblsaldo.setText(String.valueOf(resultado));
progresodia.setProgress(abono);
progresoplata.setProgress(resultado);
progreoscargando.setIndeterminate(true);
pagarSQL(resultado,codigo,observacion);
update();
}
});
llamar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String telefono = lbltelefono.getText().toString();
mensajeToast("Llamando..."+telefono);
progreoscargando.setIndeterminate(false);
}
});
return vista;
}
The code of the button in the getView is this
pagar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int abn = Integer.parseInt(ListaObejtos.get(position).getAbono().toString());
int sal = Integer.parseInt(ListaObejtos.get(position).getSaldo().toString());
int abono = Integer.parseInt(lblabono.getText().toString());
int saldo = Integer.parseInt(lblsaldo.getText().toString());
String codigo = ListaObejtos.get(position).getCodigo().toString();
String observacion = lblobservacion.getText().toString();
final int resultado = saldo-abono;
mensajeToast("Abono "+abono);
lblsaldo.setText(String.valueOf(resultado));
progresodia.setProgress(abono);
progresoplata.setProgress(resultado);
progreoscargando.setIndeterminate(true);
pagarSQL(resultado,codigo,observacion);
update();
}
});
The paySQL event which is responsible for modifying the balance in the SQLite database
private void pagarSQL(int saldo,String codigo,String observacion){
BaseDatos admin = new BaseDatos(context,
"admin", null, 1);
SQLiteDatabase bd = admin.getWritableDatabase();
ContentValues registro = new ContentValues();
registro.put("saldo", saldo);
registro.put("observacion", observacion);
registro.put("diapago",fechaActual());
int cant = bd.update("clientes", registro, "codigo=" + codigo, null);
bd.close();
if (cant == 1) {
lblsaldo.setText(saldo);
HacerPagos2 i = new HacerPagos2();
i.notificacion("Pago realizado localmente ", Color.GREEN);
}
}
When I press the button, all the balances of all the registered data with the same balance of the item are updated, it is as if I went through a record-by-record loop, changing all the balances by the balance of the item changed