I am developing an application that consumes web services ( Web Services ), it is already advanced and I am now filling a ListView
through a custom adapter a detail which brings information such as the balance and balance due, and a EditText
in which they will digital how much was paid to each note that customer has.
But I find myself in the detail, that I have a button that when clicked must go through each item on my list and check the EditText
and if it has any data it will add it and the total will be sent by another method via services web, but I really do not know how to do that operation, how could I do it?
I certainly use the Asynctask
for the call of the Web Services .
This is my code where I send my detail and where the button will be executed
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent1=getIntent();
setContentView(R.layout.activity_detalle__cliente);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent=getIntent();
O_Cliente=(CXCPSaldoClienteProveedor) intent.getSerializableExtra("O_Cliente");
setTitle(O_Cliente.getClienteDescripcion());
//codigo listview
list=(ListView)this.findViewById(R.id.listDeta);
AsyncCallWSDetalle task = new AsyncCallWSDetalle();
//Call execute
task.execute();
//codigo proceso de pago
Button pagar = (Button)this.findViewById(R.id.btnpago);
pagar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
AsyncGrabarCXCP task = new AsyncGrabarCXCP();
//Call execute
list=(ListView)this.findViewById(R.id.listDeta);
for(int i=0;i<list.getCount();i++){
View view=list.getChildAt(i);
EditText edt_abono = (EditText) view.findViewById(R.id.edt_abono);
//DetalleCxP R_DetalleCxP = (DetalleCxP)((TextView)view.findViewById(R.id.txtFolio)).getTag();
String string=edt_abono.getText().toString();
String string=editText.getText().toString();
if(!string.equals(""))
total+=Double.parseDouble(string);
}
task.execute();
}
});
}
private class AsyncCallWSDetalle extends AsyncTask<String, ArrayList, ArrayList> {
@Override
protected ArrayList doInBackground(String... params){
DetalleArrayList=webService.DetalleCxP(O_Cliente.getCliente());
return null;
}
@Override
//Make Progress Bar visible
protected void onPreExecute() {
dialog=new ProgressDialog(Detalle_Cliente.this);
dialog.setIndeterminate(false);
dialog.setMessage("Cargando Detalle...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected void onProgressUpdate(ArrayList... values) {
super.onProgressUpdate(values);
}
//Once WebService returns response
@Override
protected void onPostExecute(ArrayList arrayList) {
super.onPostExecute(arrayList);
if(DetalleArrayList.size()!=0){
dialog.dismiss();
adaptador= new MyArrayAdapter(Detalle_Cliente.this, DetalleArrayList);///* no se usa your_array_list
ListView listView = (ListView) findViewById(R.id.listDeta);
listView.setAdapter(adaptador);
}else{
dialog.dismiss();
}
}
}
public class MyArrayAdapter extends ArrayAdapter<DetalleCxP> {
public MyArrayAdapter(Context context, ArrayList<DetalleCxP> ArrayClientes) {
super(context, 0, ArrayClientes);
}
public View getView(int position, View convertView, ViewGroup parent) {
DetalleCxP O_DetalleCxP = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_detalle, parent, false);
}
//Obteniendo instancias de los text views
TextView fecha = (TextView)convertView.findViewById(R.id.txtFecha);
TextView folio = (TextView)convertView.findViewById(R.id.txtFolio);
TextView vencido = (TextView)convertView.findViewById(R.id.txtvencido);
TextView saldo = (TextView)convertView.findViewById(R.id.txttotal);
// EditText opcionOtros = (EditText) convertView.findViewById(R.id.edt_abono);
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
fecha.setText(dateFormat.format(O_DetalleCxP.getFecha()));
folio.setText(O_DetalleCxP.getFolio());
folio.setTag(O_DetalleCxP);
vencido.setText(numberFormat.format(O_DetalleCxP.getSaldoVencido()));
saldo.setText(numberFormat.format(O_DetalleCxP.getSaldo()));
//Devolver al ListView la fila creada
return convertView;
}
}
public class AsyncGrabarCXCP extends AsyncTask<Void,Integer,Integer>
{
int Recurso;
Double Importe, Descuento, SubTotal, Total, Saldo;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog=new ProgressDialog(Detalle_Cliente.this);
dialog.setIndeterminate(false);
dialog.setMessage("Procesando Datos...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected Integer doInBackground(Void... params) {
Recurso=webService.ObtenerRecurso();
String Folio = webService.ObtenerFolio(35);
Date O_D = new Date();
return null;
}
@Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
}
}
}