Scroll listview and add edittext data

4

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);
        }
    }
}
    
asked by Hugo Rodriguez 10.05.2016 в 23:26
source

1 answer

2

There are many ways but the one I recommend the most is to create a global ArrayList.

This ArrayList must be entered in the Listview Adapter but you must reference

ArrayList<DetalleCxP> ArrayClientes;
public MyArrayAdapter(Context context, ArrayList<DetalleCxP> ArrayClientes) {
    super(context, 0, ArrayClientes);
    this.ArrayClientes = ArrayClientes;
}

And in the getView something like that;

public View getView(int position, View convertView, ViewGroup parent) {
        //Esto en lugar del getItem(position);
        DetalleCxP O_DetalleCxP = ArrayClientes.get(position);
        //Tu código sigue igual
...

Now remember that the ArrayClients must pass it from the onCreate for when you press the button the changes are saved in the ArrayList and you must put a value in your "DetailCxP" class that makes reference to the editext, with this (even if it sounds strange) will happen the following

ArrayClientes.get(position).editText = (EditText) convertView.findViewById(R.id.edt_abono);

Now in the onCreate when you click on the button you go through the arrayList one by one and put the following for example:

for (int x = 0; x < ArrayClientes.length; x++) {
    String valor = ArrayClientes.get(position).editText.getText().toString();
    //Lo que quieras hacer con el valor...
}

This is object-oriented programming and reference of objects: D, luck

PD. Remember that in your DetailCxP class you must add an EditText attribute editText; Assuming you want it to work as I put it, put it public, if you put it private do your setter and getter

    
answered by 12.05.2016 в 20:17