I have a listview which is filled with Arrayadapater
custom with data I get from my SQLite bd.
The detail is that I need to insert a flag or an identifier in every detail of listview
that shows me for example the listview
can show me 4 rows with their details and there is a edittext
which the user enter a quantity, then the user may only enter a quantity in the first line or the others leave blank, then I have a for where I go through my array
and make a sum and then apply the payment, the detail is when I apply the payment affects me all the lines and it should not be like that, I leave my code:
Method where my array
is collected and I do the addition and I update to my tables
public void LLenarDetalle()
{
boolean PagoCeros=false;
boolean Activo=false;
String Referencia = "", Folio = "";
int Cliente = 0;
Double Factor=0.0, Importe=0.0, Descuento=0.0, SubTotal=0.0, Total=0.0, IVA=0.0,Retencion1=0.0,Retencion2=0.0,IEPS=0.0, ISH=0.0, Financiamiento=0.0, SaldoC = 0.0, SaldoV = 0.0;
Double DFactor=0.0;
for(int i=0;i<DetalleArrayList.size();i++) {
if (((((CXCPDetalle)DetalleArrayList.get(i)).TotalAplicado>0) && (PagoCeros==false)) || ((((CXCPDetalle)DetalleArrayList.get(i)).TotalAplicado==0) && (PagoCeros==true)))
{
DFactor = ((CXCPDetalle)DetalleArrayList.get(i)).TotalAplicado / ((CXCPDetalle)DetalleArrayList.get(i)).Total;
Importe += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).Importe*DFactor); //Importe
Financiamiento += (Double)0.0; //Financiamiento
Descuento += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).Descuento*DFactor); //Descuento
SubTotal += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).SubTotal*DFactor); //Subtotal
Retencion1 += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).Retencion1*DFactor); //Retencion1
Retencion2 += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).Retencion2*DFactor); //Retencion2
IEPS += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).IEPS*DFactor); //IEPS
IVA += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).IVA*DFactor); //IVA
ISH += (Double)0.0; //ISH
Total += (Double)(((CXCPDetalle)DetalleArrayList.get(i)).Total*DFactor); //Total
SaldoC += ((CXCPDetalle)DetalleArrayList.get(i)).Saldo-DetalleArrayList.get(i).TotalAplicado; //Saldo
Referencia = "Android App Desconectado";//Referencia
Cliente = ((CXCPDetalle)DetalleArrayList.get(i)).getCliente();
Folio = ((CXCPDetalle)DetalleArrayList.get(i)).getFolio();
}
}
int i = 0;
ContentValues Newvalues = new ContentValues();
Newvalues.put(SqliteDB.DBhelper.COLUMN_NAME_Saldo, SaldoC);
ContentValues newValues = new ContentValues();
newValues.put(SqliteDB.DBhelper.COLUMN_NAME_SAldo, SaldoC);
update(SqliteDB.DBhelper.TABLE_NAME_DETA ,newValues,SqliteDB.DBhelper.COLUMN_NAME_CLiente + " = " + Cliente + SqliteDB.DBhelper.COLUMN_NAME_Folio + " = " + Folio,null);
update(SqliteDB.DBhelper.TABLE_NAME, Newvalues, SqliteDB.DBhelper.COLUMN_NAME_Cliente + " = " + Cliente,null);
finish();
}
Code Techwatcher
which works when I insert an amount in edittext
add it up
private class TB_Abono_Watcher implements TextWatcher{
Button pagar =(Button)findViewById(R.id.pago);
private View view;
private TB_Abono_Watcher(View view) {
this.view = view;
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s)
{
CXCPDetalle O_CXCPDetalle = (CXCPDetalle)((EditText)view.findViewById(R.id.edt_abono)).getTag();
SharedPreferences settings = getSharedPreferences("ONC_Settings", 0);
if (settings.getInt("ONControlConexion",0) == 0) {
if (O_CXCPDetalle.getViewChanged()==false) {
O_CXCPDetalle.TotalAplicado = ONC_SYS.NullToZeroDouble(s.toString());
Double Total = 0.0;
for (int i = 0; i < O_Resultado.DetalleArray.size(); i++) {
if (((CXCPDetalle) O_Resultado.DetalleArray.get(i)).TotalAplicado > 0) {
Total += ((CXCPDetalle) O_Resultado.DetalleArray.get(i)).TotalAplicado;
}
}
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
((TextView) findViewById(R.id.Total)).setText(numberFormat.format(Total));
if (Total == 0) {
((Button) findViewById(R.id.pagoceros)).setEnabled(true);
((Button) findViewById(R.id.pago)).setEnabled(false);
} else {
((Button) findViewById(R.id.pagoceros)).setEnabled(false);
((Button) findViewById(R.id.pago)).setEnabled(true);
}
//Validacion que no te deje hacer un abono Mayo al saldo vencido
if (O_CXCPDetalle.getSaldo() < O_CXCPDetalle.TotalAplicado) {
Toast.makeText(getApplicationContext(), "No puedes Aplicar un Abono Mayor al SaldoVencido", Toast.LENGTH_SHORT).show();
((EditText) view.findViewById(R.id.edt_abono)).setText("");
}
}
}else
{
if (O_CXCPDetalle.getViewChanged()==false) {
O_CXCPDetalle.TotalAplicado = ONC_SYS.NullToZeroDouble(s.toString());
Double Total = 0.0;
for (int i = 0; i < DetalleArrayList.size(); i++) {
if (((CXCPDetalle) DetalleArrayList.get(i)).TotalAplicado > 0) {
Total += ((CXCPDetalle) DetalleArrayList.get(i)).TotalAplicado;
}
}
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
((TextView) findViewById(R.id.Total)).setText(numberFormat.format(Total));
if (Total == 0) {
((Button) findViewById(R.id.pagoceros)).setEnabled(true);
((Button) findViewById(R.id.pago)).setEnabled(false);
} else {
((Button) findViewById(R.id.pagoceros)).setEnabled(false);
((Button) findViewById(R.id.pago)).setEnabled(true);
}
//Validacion que no te deje hacer un abono Mayo al saldo vencido
if (O_CXCPDetalle.getSaldo() < O_CXCPDetalle.TotalAplicado) {
Toast.makeText(getApplicationContext(), "No puedes Aplicar un Abono Mayor al SaldoVencido", Toast.LENGTH_SHORT).show();
((EditText) view.findViewById(R.id.edt_abono)).setText("");
}
}
}
}
}
Arrayadapter
where I fill my adapter
public class MyArrayAdapter extends ArrayAdapter<CXCPDetalle> {
public MyArrayAdapter(Context context, ArrayList<CXCPDetalle> ArrayClientes) {
super(context, 0, ArrayClientes);
}
public View getView(int position, View convertView, ViewGroup parent) {
CXCPDetalle O_CXCPDetalle = getItem(position);
if (convertView == null)
{
convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_detalle, parent, false);
((EditText) convertView.findViewById(R.id.edt_abono)).addTextChangedListener(new TB_Abono_Watcher(convertView));
}
((EditText) convertView.findViewById(R.id.edt_abono)).setTag(O_CXCPDetalle);
if(O_CXCPDetalle.TotalAplicado != 0){
((EditText) convertView.findViewById(R.id.edt_abono)).setText(String.valueOf(O_CXCPDetalle.TotalAplicado));
}
else {
((EditText)convertView.findViewById(R.id.edt_abono)).setText("");
}
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
// ((TextView)convertView.findViewById(R.id.txtFecha)).setText(dateFormat.format(O_CXCPDetalle.getFecha()));
((TextView)convertView.findViewById(R.id.txtFolio)).setText(O_CXCPDetalle.getFolio());
((TextView)convertView.findViewById(R.id.total)).setText(numberFormat.format(O_CXCPDetalle.getTotal()));
((TextView)convertView.findViewById(R.id.txttotal)).setText(numberFormat.format(O_CXCPDetalle.getSaldo()));
((TextView)convertView.findViewById(R.id.txtvencido)).setText(numberFormat.format(O_CXCPDetalle.getSaldoVencido()));
((TextView)convertView.findViewById(R.id.parcialidad)).setText((numberFormat.format(O_CXCPDetalle.getParcialidadTotal()) +" - "+ O_CXCPDetalle.getParcialidad()));
((TextView)convertView.findViewById(R.id.pagoforma)).setText(O_CXCPDetalle.getPagoCondicionDescripcion());
((TextView)convertView.findViewById(R.id.UltimoCobroObservacion)).setText(O_CXCPDetalle.getUltimoCobroObservacion());
double Abono = 0.0;
Abono = O_CXCPDetalle.getTotal()- O_CXCPDetalle.getSaldo();
((TextView)convertView.findViewById(R.id.pagado)).setText(numberFormat.format(Abono));
//Devolver al ListView la fila creada
return convertView;
}
}
I leave you the details screen