Good morning
I have a problem with a listview ... that I fill in from a webservices, and in each item that I paint there is a checkbox which when clicking I must activate the edittex of that item .. the problem is that if you I click on the first check of the first item, and scroll down my scroll I see that I doubled that check in another item that should not be, I leave code from my techwacher and my adapter.
Techwatcher Code
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) {
final CXCPDetalle o_CXCP_Detalle = (CXCPDetalle) ((EditText) view.findViewById(R.id.edt_abono)).getTag();
SharedPreferences settings = getSharedPreferences("ONC_Settings", 0);
if (settings.getInt("ONControlConexion", 0) == 0) {
if (o_CXCP_Detalle.getViewChanged() == false) {
o_CXCP_Detalle.TotalAplicado = ONC_SYS.NullToZeroDouble(s.toString());
final Double Total = _TotalAplicado();
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
((TextView) findViewById(R.id.Total)).setText(numberFormat.format(Total));
((CheckBox) view.findViewById(R.id.checkBox)).setEnabled(true);
((CheckBox) view.findViewById(R.id.checkBox)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences settings = getSharedPreferences("ONC_Settings", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("ONControlCheck", String.valueOf(isChecked));
editor.commit();
o_CXCP_Detalle.setStatusCheck(String.valueOf(isChecked));
if (o_CXCP_Detalle.getStatusCheck() == "true") {
((Button) findViewById(R.id.pago)).setEnabled(true);
((EditText) view.findViewById(R.id.edt_abono)).setEnabled(true);
} else {
Double TotalAplicado = Total;
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
((EditText) view.findViewById(R.id.edt_abono)).setText("");
((EditText) view.findViewById(R.id.edt_abono)).setEnabled(false);
TotalAplicado = _TotalAplicado();
((TextView) findViewById(R.id.Total)).setText(numberFormat.format(TotalAplicado));
}
}
});
if (o_CXCP_Detalle.getStatusCheck() == "true") {
((Button) findViewById(R.id.pago)).setEnabled(true);
((EditText) view.findViewById(R.id.edt_abono)).setEnabled(true);
} else {
((EditText) view.findViewById(R.id.edt_abono)).setEnabled(false);
}
//Validacion que no te deje hacer un abono Mayo al saldo vencido
if (o_CXCP_Detalle.getSaldo() < o_CXCP_Detalle.TotalAplicado) {
Toast.makeText(getApplicationContext(), "No puedes Aplicar un Abono Mayor al SaldoVencido", Toast.LENGTH_SHORT).show();
((EditText) view.findViewById(R.id.edt_abono)).setText("");
}
}
Adapter Code
public class CustomAdapter extends ArrayAdapter<CXCPDetalle> {
private Detalle_Cliente dataSet;
Context mContext;
boolean[] checkBoxState;
// View lookup cache
public class ViewHolder {
public TextView txfecha = null;
public TextView txfolio = null;
public TextView txtotal = null;
public TextView txttotal = null;
public TextView vencido = null;
public TextView parcialidad = null;
public TextView pagoforma = null;
public TextView ultimocobroob = null;
public CheckBox checkBox = null;
public EditText cantidad;
}
public CustomAdapter(Detalle_Cliente data, ArrayList context) {
super(data, R.layout.row_detalle, context);
this.dataSet = data;
}
private int lastPosition = -1;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// Get the data item for this position
final CXCPDetalle O_CXCPDetalle = getItem(position);
// final ListViewItem item = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
final ViewHolder viewHolder; // view lookup cache stored in tag
final View result;
if (convertView == null) {
viewHolder = new ViewHolder();
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)).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("");
}
viewHolder.txfecha = (TextView) convertView.findViewById(R.id.txtFecha);
viewHolder.txfolio = (TextView) convertView.findViewById(R.id.txtFolio);
viewHolder.txtotal = (TextView) convertView.findViewById(R.id.total);
viewHolder.txttotal = (TextView) convertView.findViewById(R.id.txttotal);
viewHolder.vencido = (TextView) convertView.findViewById(R.id.txtvencido);
viewHolder.parcialidad = (TextView) convertView.findViewById(R.id.parcialidad);
viewHolder.pagoforma = (TextView) convertView.findViewById(R.id.pagoforma);
viewHolder.ultimocobroob = (TextView) convertView.findViewById(R.id.UltimoCobroObservacion);
viewHolder.checkBox = (CheckBox)convertView.findViewById(R.id.checkBox);
viewHolder.checkBox.setTag(new Integer(position));
result = convertView;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
result = convertView;
// viewHolder.checkBox.setOnCheckedChangeListener(null);
}
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
viewHolder.checkBox.setFocusable(false);
viewHolder.txfecha.setText(dateFormat.format(O_CXCPDetalle.getFecha()));
viewHolder.txfolio.setText(O_CXCPDetalle.getFolio());
viewHolder.txtotal.setText(numberFormat.format(O_CXCPDetalle.getTotal()));
viewHolder.txttotal.setText(numberFormat.format(O_CXCPDetalle.getSaldo()));
viewHolder.vencido.setText(numberFormat.format(O_CXCPDetalle.getSaldoVencido()));
viewHolder.parcialidad.setText((numberFormat.format(O_CXCPDetalle.getParcialidadTotal()) + " - " + O_CXCPDetalle.getParcialidad()));
viewHolder.pagoforma.setText(O_CXCPDetalle.getPagoCondicionDescripcion());
viewHolder.ultimocobroob.setText(O_CXCPDetalle.getUltimoCobroObservacion());
viewHolder.checkBox.setEnabled(true);
double Abono = 0.00;
Abono = O_CXCPDetalle.getTotal() - O_CXCPDetalle.getSaldo();
((TextView) convertView.findViewById(R.id.pagado)).setText(numberFormat.format(Abono));
// Return the completed view to render on screen
return convertView;
}
}