I am developing an app, in which I have a listview in which I load information and I have several controls, I have a checkbox that when clicked activates an edittext so that the user can write about it.
The detail that I have with the checkbox is that for example I select the first check but if I go through my listview down I see other check that I do not select.
I leave you code and an image.
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());
Double Total = 0.00;
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));
((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
{
((EditText) view.findViewById(R.id.edt_abono)).setEnabled(false);
}
}
});
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("");
}
}
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) {
final 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.00;
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;
}
}
public MyArrayAdapter(Context context, ArrayList<CXCPDetalle> ArrayClientes) {
super(context, 0, ArrayClientes);
}
class ViewHolderCustom{
TextView FECHA;
TextView FOLIO;
TextView TOTAL;
TextView SALDO;
TextView VENCIDO;
TextView PARCIALIDAD;
TextView PAGOFORMA;
TextView OBSERVACION;
}
ViewHolderCustom holder;
public View getView(int position, View convertView, ViewGroup parent) {
final 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));
holder = new ViewHolderCustom();
holder.FECHA = (TextView) convertView.findViewById(R.id.txtFecha);
holder.FOLIO = (TextView) convertView.findViewById(R.id.txtFolio);
holder.TOTAL = (TextView) convertView.findViewById(R.id.total);
holder.SALDO = (TextView) convertView.findViewById(R.id.txttotal);
holder.VENCIDO = (TextView) convertView.findViewById(R.id.txtvencido);
holder.PARCIALIDAD = (TextView) convertView.findViewById(R.id.parcialidad);
holder.PAGOFORMA = (TextView) convertView.findViewById(R.id.pagoforma);
holder.OBSERVACION = (TextView) convertView.findViewById(R.id.UltimoCobroObservacion);
convertView.setTag(holder);
}
((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");
holder.FECHA.setText(dateFormat.format(O_CXCPDetalle.getFecha()));
holder.FOLIO.setText(O_CXCPDetalle.getFolio());
holder.TOTAL.setText(numberFormat.format(O_CXCPDetalle.getTotal()));
holder.SALDO.setText(numberFormat.format(O_CXCPDetalle.getSaldo()));
holder.VENCIDO.setText(numberFormat.format(O_CXCPDetalle.getSaldoVencido()));
holder.PARCIALIDAD.setText((numberFormat.format(O_CXCPDetalle.getParcialidadTotal()) + " - " + O_CXCPDetalle.getParcialidad()));
holder.PAGOFORMA.setText(O_CXCPDetalle.getPagoCondicionDescripcion());
holder.OBSERVACION.setText(O_CXCPDetalle.getUltimoCobroObservacion());
double Abono = 0.00;
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;
}