Convert String to decimals android studio

2

I'm developing an app in android studio, the app is already somewhat advanced and only things are being fine-tuned, such as sending me through a webservices in asmx which I am consuming with SOAP, sending me a method called CXCPSaldoDocumento which with a filter, all the clients are thrown, which I take the data I turn them into objects and then display them in a personalized listview, but the problem is that when I want to format the numbers so that I accept decimals, it does not changes, according to me is because I have them in string and I have to convert them into decimal or another format, I need your help ... I leave my codes ..

method call webservices client

public static ArrayList<Cliente> Clientes() {

    // Create request
    SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9020/","CXCPSaldoDocumento");
    request.addProperty("Documento", "35");
    request.addProperty("Cliente", "0");
    request.addProperty("Proveedor", "0");
    request.addProperty("Moneda", "0");
    request.addProperty("Filtro", "E");
    request.addProperty("FiltroAdicional", " ");
    // Property which holds input parameters

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.implicitTypes=false;
    // Set output SOAP object
    envelope.setOutputSoapObject(request);
    // Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);

    ArrayList<Cliente> ClienteArray = new ArrayList<Cliente>();

    //ArrayAdapter<String>  arrayadapter;
    try {
        androidHttpTransport.debug=true;
        // Invoke web service
        androidHttpTransport.call("http://oncontrol.no-ip.net:9020/CXCPSaldoDocumento", envelope);
        String ss=androidHttpTransport.responseDump;
        SoapObject response = (SoapObject)envelope.getResponse();

        SoapObject obj1 = (SoapObject) envelope.getResponse();

        SoapObject obj2 =(SoapObject) obj1.getProperty(1);

        SoapObject obj3 =(SoapObject) obj2.getProperty(0);

        for(int i=0; i<obj3.getPropertyCount(); i++)
        {

            SoapObject obj4 =(SoapObject) obj3.getProperty(i);
            String Cliente = obj4.getProperty("Cliente").toString();
            String ClienteDescripcion = obj4.getProperty("ClienteDescripcion").toString();
            String Saldo = obj4.getProperty("Saldo").toString();
            String SaldoVencido = obj4.getProperty("SaldoVencido").toString();
            Cliente newCliente = new Cliente(ClienteDescripcion, SaldoVencido, Saldo);
            ClienteArray.add(newCliente);

        }

    } catch (Exception e) {
        //Assign Error Status true in static variable 'errored'
        //menu.errored = true;
        e.printStackTrace();
    }
    //Return booleam to calling object
    //return loginStatus;

    return ClienteArray;
}

Custom arrayadapter code:

public class MyArrayAdapter extends ArrayAdapter<Cliente> {

  public MyArrayAdapter(Context context, ArrayList<Cliente> ArrayClientes) {
      super(context, 0, ArrayClientes);
  }

  public View getView(int position, View convertView, ViewGroup parent) {

      Cliente O_Cliente = 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 nombre = (TextView) convertView.findViewById(R.id.nombrecli);
      TextView saldo = (TextView) convertView.findViewById(R.id.saldo);
      TextView saldov = (TextView) convertView.findViewById(R.id.saldov);

      nombre.setText(O_Cliente.getClienteDescripcion());
      saldo.setText(O_Cliente.getCliente());
      saldov.setText(O_Cliente.getSaldo());

      //Devolver al ListView la fila creada
      return convertView;

  }
}
    
asked by Hugo Rodriguez 05.05.2016 в 01:59
source

1 answer

3

Assuming that the values of String of the variables Saldo and SaldoVencido have the following values:

Saldo = "12.324";
SaldoVencido = "52.4355";

You can convert to Double from the String values:

 Double dSaldo =  Double.valueOf(Saldo);
 Double dSaldoVencido =  Double.valueOf(SaldoVencido);

getting the values:

12.324
52.4355

In the case of your example, I see that in the Adapter you add the values to your TextView , saldo and saldov , the values would not need to be changed, it seems to me that the problem is that the values you enter they are incorrect, it must be something like:

... 
saldo.setText(O_Cliente.getSaldo()); //Saldo
saldov.setText(O_Cliente.getSaldoVencido()); //SaldoVencido
...
    
answered by 05.05.2016 / 05:27
source