stepstone-tech / android-material-stepper

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

how to send Data from StepperAdapter to myStepsFragment ? #276

Open yudikarma opened 5 years ago

yudikarma commented 5 years ago

thanks for awesome third-party library :+1: i was try to send data from StepperAdapter to fragment like this :

in my stepperAdapter : switch (position){ case 0: final SetTitleFragment setTitleFragment = new SetTitleFragment(); Bundle b1 = new Bundle(); b1.putInt(CURRENT_STEP_POSITION_KEY,position); b1.putInt("id_from_adapter",10); setTitleFragment.setArguments(b1); return (Step) setTitleFragment;

in myStepperFragment : Bundle bundle = new Bundle();

    if (getArguments() != null){
        int id = bundle.getInt("id_from_adapter");
        Toast.makeText(getActivity(),"id_edit = "+id,Toast.LENGTH_SHORT).show();
    }

but i not get the data. the toast result just 0 or NULL

how to do ? please tell me Thanks

jumaallan commented 5 years ago

I also need help on the same issue

zawadz88 commented 5 years ago

Hi, Sorry for not responding sooner. Could you please explain where you're setting these arguments and where you're reading them in the fragment?

in myStepperFragment : Bundle bundle = new Bundle(); if (getArguments

This seems a bit suspicious to me i.e. why would you create a new bundle in the Fragment?

Passing the position to each fragment can be done as in the sample app: https://github.com/stepstone-tech/android-material-stepper/blob/master/sample/src/main/java/com/stepstone/stepper/sample/adapter/StepperFeedbackFragmentStepAdapter.kt https://github.com/stepstone-tech/android-material-stepper/blob/master/sample/src/main/java/com/stepstone/stepper/sample/step/fragment/StepperFeedbackStepFragment.kt

jumaallan commented 5 years ago

My question was actually this - How do i best pass data across 2 stepper fragments?

zawadz88 commented 5 years ago

There's a sample in the sample app which you might have a look at: https://github.com/stepstone-tech/android-material-stepper/blob/master/sample/src/main/java/com/stepstone/stepper/sample/PassDataBetweenStepsActivity.kt https://github.com/stepstone-tech/android-material-stepper/blob/master/sample/src/main/java/com/stepstone/stepper/sample/adapter/PassDataBetweenStepsFragmentStepAdapter.kt https://github.com/stepstone-tech/android-material-stepper/blob/master/sample/src/main/java/com/stepstone/stepper/sample/step/fragment/PassDataBetweenStepsFirstStepFragment.kt https://github.com/stepstone-tech/android-material-stepper/blob/master/sample/src/main/java/com/stepstone/stepper/sample/step/fragment/PassDataBetweenStepsSecondStepFragment.kt