How can I make the sum of 3 number picker 100?

55 Views Asked by At

I want to make an application with 3 number pickers. I want to find the percentage distribution of carbohydrates, fat and protein. and this 3 number picker works in coordination with each other and I want to adjust the max and min values ​​accordingly. The sum of these 3 number pickers will be 100. e.g; like 15,35,50 or 50.45.5 or 10,20,70

Screenshot

        NumberPicker carb=add_dialog.findViewById(R.id.carb);
        NumberPicker protein=add_dialog.findViewById(R.id.protein);
        NumberPicker fat=add_dialog.findViewById(R.id.fat);

        carb.setMinValue(1);
        carb.setMaxValue(99);
        protein.setMinValue(1);
        protein.setMaxValue(99);
        fat.setMinValue(1);
        fat.setMaxValue(99);

        // Initial
        carb.setValue(25);
        protein.setValue(40);
        fat.setValue(35);


        carb.setOnValueChangedListener((picker, oldVal, newVal) -> {
            protein.setMaxValue(100-(newVal+fat.getValue()));
            fat.setMaxValue(100-(newVal+protein.getValue()));
        });
      

0

There are 0 best solutions below