stepstone-tech / android-material-stepper

This library allows to use Material steppers inside Android applications.
Apache License 2.0
1.78k stars 263 forks source link

Remove or Add Steps Conditionally #283

Open Tarcisiofl opened 5 years ago

Tarcisiofl commented 5 years ago

Make sure these boxes are checked before submitting your issue - thank you!

I have a step wizard with 8 steps, and the last step is a summary of everything where the user can click on each information and go direct to this step. Therefore, when the user select some specific services on the 4 step. I need to show or hide 3 further steps.

However, I cannot find a good way to implement this behavior.

case 0:
                final CompanyFragment client = new CompanyFragment();
                Bundle bClient = new Bundle();
                bClient.putInt(CURRENT_STEP_POSITION_KEY, position);
                client.setArguments(bClient);
                return client;
case 1:
                final BuildingFragment building = new BuildingFragment();
                Bundle bBuilding = new Bundle();
                bBuilding.putInt(CURRENT_STEP_POSITION_KEY, position);
                building.setArguments(bBuilding);
                return building;
case 2:
                final ShiftFragment shift = new ShiftFragment();
                Bundle bShift = new Bundle();
                bShift.putInt(CURRENT_STEP_POSITION_KEY, position);
                shift.setArguments(bShift);
                return shift;
case 3:
                final ServiceFragment service = new ServiceFragment();
                Bundle bService = new Bundle();
                bService.putInt(CURRENT_STEP_POSITION_KEY, position);
                service.setArguments(bService);
                return service;
case 4:
                final ServiceDetailsFragment serviceDetails = new ServiceDetailsFragment();
                Bundle bServiceDetails = new Bundle();
                bServiceDetails.putInt(CURRENT_STEP_POSITION_KEY, position);
                serviceDetails.setArguments(bServiceDetails);
                return serviceDetails;
case 5:
                final CarrierFragment carrier = new CarrierFragment();
                Bundle bCarrier = new Bundle();
                bCarrier.putInt(CURRENT_STEP_POSITION_KEY, position);
                carrier.setArguments(bCarrier);
                return carrier;
case 6:
                final VehicleFragment vehicle = new VehicleFragment();
                Bundle bVehicle = new Bundle();
                bVehicle.putInt(CURRENT_STEP_POSITION_KEY, position);
                vehicle.setArguments(bVehicle);
                return vehicle;
case 7:
                final PlateFragment plate = new PlateFragment();
                Bundle bPlate = new Bundle();
                bPlate.putInt(CURRENT_STEP_POSITION_KEY, position);
                plate.setArguments(bPlate);
                return plate;
case 8:
                final SummaryFragment summary = new SummaryFragment();
                Bundle bSummary = new Bundle();
                bSummary.putInt(CURRENT_STEP_POSITION_KEY, position);
                summary.setArguments(bSummary);
                return summary;

I need to hide the case 5, 6 and 7.

hyuni commented 3 years ago

Hi

I solved a similar situation through setAdapter(adapter, step).

// in adapter
val stepList = mutableListOf(step1, step2)
val conditionList = listOf(step3, step4)
var isCondition : Boolean = false 

// set codition
fun setCondition(isCondition: Boolean) {
  this.isCondition = isCondition
  if (isCondition) {
     stepList.addAll(conditionList)
  } else {
     stepList.removeAll(conditionList
  }
}