Help with ProgressBar

1

hello I have a little problem in the following code that I will show, and that is how I can do it so that my progress bar does not go from 0 to 100, but instead of me I take a variable to get the percentage annex the progressbar code and my operation code

            //Progressbar
            ObjectAnimator anim = ObjectAnimator.ofInt(pbarra, 
            "progress", 0, 100);//En vez del 100 quiero traer el porciento de la operacion para sacar el porcentaje como le hago
            anim.setDuration(2000);
            anim.setInterpolator(new DecelerateInterpolator());
            //iniciamos el progressbar
            anim.start();

            //Operacion
            float total = (float) (articulo * cantidad);
            float total1 = (float) (inicio - total);
            float porciento = (float) ((total1 / inicio) * 100);
            String porcentaje = Float.toString(porciento);
            tvporcentaje.setText(porcentaje);
    
asked by Dan Hermes Reyes Osnaya 26.02.2018 в 00:24
source

1 answer

0

I would think it is like this

//Operacion
            float total = (float) (articulo * cantidad);
            float total1 = (float) (inicio - total);
            float porciento = (float) ((total1 / inicio) * 100);


            ObjectAnimator anim = ObjectAnimator.ofInt(pbarra, 
            "progress", 0, (int) porciento);//En vez del 100 quiero traer el porciento de la operacion para sacar el porcentaje como le hago
            anim.setDuration(2000);
            anim.setInterpolator(new DecelerateInterpolator());
            //iniciamos el progressbar
            anim.start();

            String porcentaje = Float.toString(porciento);
            tvporcentaje.setText(porcentaje);
    
answered by 26.02.2018 в 16:32