En android kotlin utilizando la biblioteca paso a paso pasando los valores de botones de opción personalizados sobre múltiples fragments para ser usados ​​en una página de resumen

Hola, espero que ustedes puedan ayudarme. Estoy bastante seguro de que estoy cerca de responder, pero parece que no puede hacerlo bien.

Lo que tengo configurado son 12 fragments de configuration usando la biblioteca stepper-tech stepper

Cada fragment less el fragment de resumen tiene su propio Grupo de Radio que representa una pregunta con cada Botón de Radio asignado un valor a través de una label (necesita tener su valor único para ser calculado en el fragment de resumen).

Cada fragment está configurado para requerir una respuesta antes de que se le permita moverse al siguiente fragment.

Todo esto funciona sin problemas y como espero, pero estoy luchando para encontrar la forma de extraer el valor labeldo, savelo con mi interfaz DataManager y llevarlo al fragment de resumen con mi function onNextClick.

PulseFragment

class PulseFragment : Fragment(), BlockingStep { companion object { fun newInstance(): PulseFragment { return PulseFragment() } } @BindView(R.id.pulseGroup) lateinit var pulseGroup: RadioGroup lateinit var dataManager: DataManager override fun onAttach(context: Context?) { super.onAttach(context) if (context is DataManager) { dataManager = context } else { throw IllegalStateException("Activity must implement DataManager interface!") } } override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { //initialize your UI return inflater!!.inflate(R.layout.fragment_pulse, container, false) } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val rg1 = view!!.findViewById<View>(R.id.pulseGroup) as RadioGroup rg1.setOnCheckedChangeListener { group, checkedId -> val context = context val thisButton = getView()!!.findViewById<View>(checkedId) as RadioButton val toast = Toast.makeText(context, thisButton.text, Toast.LENGTH_SHORT) toast.show() ButterKnife.bind(this, view) } } override fun onNextClicked(callback: StepperLayout.OnNextClickedCallback) { val selectedRadio = pulseGroup.toString() dataManager.saveData(selectedRadio) callback.goToNextStep() } override fun onCompleteClicked(callback: StepperLayout.OnCompleteClickedCallback) { } override fun onBackClicked(callback: StepperLayout.OnBackClickedCallback) { Toast.makeText(this.getContext(), "You went back a step!", Toast.LENGTH_SHORT).show() callback.goToPrevStep() } override fun verifyStep(): VerificationError? { val rg1 = view!!.findViewById<View>(R.id.pulseGroup) as RadioGroup return if (rg1.getCheckedRadioButtonId() == -1) VerificationError("Please select an answer!") else null } override fun onSelected() { } override fun onError(error: VerificationError) { } val layoutResId: Int get() = R.layout.fragment_pulse } 

StepperAdapter

 class StepperAdapter(fm: FragmentManager, context: Context) : AbstractFragmentStepAdapter(fm, context) { override fun createStep(position: Int): Step? { when (position) { 0 -> { val step1 = PulseFragment() val b1 = Bundle() b1.putInt(CURRENT_STEP_POSITION_KEY, position) step1.arguments = b1 return step1 } 1 -> { val step2 = SweatingFragment() val b2 = Bundle() b2.putInt(CURRENT_STEP_POSITION_KEY, position) step2.arguments = b2 return step2 } 2 -> { val step3 = RestlessnessFragment() val b3 = Bundle() b3.putInt(CURRENT_STEP_POSITION_KEY, position) step3.arguments = b3 return step3 } 3 -> { val step4 = PupilFragment() val b4 = Bundle() b4.putInt(CURRENT_STEP_POSITION_KEY, position) step4.arguments = b4 return step4 } 4 -> { val step5 = BoneFragment() val b5 = Bundle() b5.putInt(CURRENT_STEP_POSITION_KEY, position) step5.arguments = b5 return step5 } 5 -> { val step6 = RunnyFragment() val b6 = Bundle() b6.putInt(CURRENT_STEP_POSITION_KEY, position) step6.arguments = b6 return step6 } 6 -> { val step7 = GiFragment() val b7 = Bundle() b7.putInt(CURRENT_STEP_POSITION_KEY, position) step7.arguments = b7 return step7 } 7 -> { val step8 = TremorFragment() val b8 = Bundle() b8.putInt(CURRENT_STEP_POSITION_KEY, position) step8.arguments = b8 return step8 } 8 -> { val step9 = YawningFragment() val b9 = Bundle() b9.putInt(CURRENT_STEP_POSITION_KEY, position) step9.arguments = b9 return step9 } 9 -> { val step10 = AnxietyFragment() val b10 = Bundle() b10.putInt(CURRENT_STEP_POSITION_KEY, position) step10.arguments = b10 return step10 } 10 -> { val step11 = GoosefleshFragment() val b11 = Bundle() b11.putInt(CURRENT_STEP_POSITION_KEY, position) step11.arguments = b11 return step11 } 11 -> { val step12 = SummaryFragment() val b12 = Bundle() b12.putInt(CURRENT_STEP_POSITION_KEY, position) step12.arguments = b12 return step12 } } return null } override fun getCount(): Int { return 12 } override fun getViewModel(@IntRange(from = 0) position: Int): StepViewModel { val builder = StepViewModel.Builder(context) .setTitle(R.string.tab_title) when (position) { 0 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Cancel") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(StepViewModel.NULL_DRAWABLE) 1 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 2 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 3 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 4 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 5 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 6 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 7 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 8 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 9 -> builder .setEndButtonLabel("This way") .setBackButtonLabel("Go back") .setNextButtonEndDrawableResId(R.drawable.ic_arrow_forward_black_24dp) .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 10 -> builder .setEndButtonLabel(R.string.go_to_summary) .setBackButtonLabel("Go to first") .setBackButtonStartDrawableResId(R.drawable.ic_arrow_back_black_24dp) 11 -> builder .setBackButtonLabel("Go back") .setEndButtonLabel("I'm done!") else -> throw IllegalArgumentException("Unsupported position: " + position) } return builder.create() } companion object { private val CURRENT_STEP_POSITION_KEY = "messageResourceId" } } 

Actividad principal

 class MainActivity : AppCompatActivity(), StepperLayout.StepperListener { private var mStepperLayout: StepperLayout? = null private var mStepperAdapter: StepperAdapter? = null override fun onCreate(savedInstanceState: Bundle?) { setTheme(R.style.MyMaterialTheme) super.onCreate(savedInstanceState) setContentView(R.layout.test_layout) mStepperLayout = findViewById<View>(R.id.stepperLayout) as StepperLayout mStepperAdapter = StepperAdapter(supportFragmentManager, this) mStepperLayout!!.adapter = mStepperAdapter!! mStepperLayout!!.setListener(this) } override fun onCompleted(completeButton: View) { Toast.makeText(this, "Hope this helped!", Toast.LENGTH_SHORT).show() } override fun onError(verificationError: VerificationError) { Toast.makeText(this, "" + verificationError.errorMessage, Toast.LENGTH_SHORT).show() } override fun onStepSelected(newStepPosition: Int) {} override fun onReturn() { finish() } } 

PassDataBetweenStepsActivity

 class PassDataBetweenStepsActivity : AppCompatActivity(), DataManager { companion object { private const val CURRENT_STEP_POSITION_KEY = "position" private const val DATA = "data" } @BindView(R.id.stepperLayout) lateinit var stepperLayout: StepperLayout private var data: String? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) title = "Stepper sample" setContentView(R.layout.test_layout) ButterKnife.bind(this) val startingStepPosition = savedInstanceState?.getInt(CURRENT_STEP_POSITION_KEY) ?: 0 data = savedInstanceState?.getString(DATA) stepperLayout.setAdapter(PassDataBetweenStepsFragmentStepAdapter(supportFragmentManager, this), startingStepPosition) } override fun onSaveInstanceState(outState: Bundle) { outState.putInt(CURRENT_STEP_POSITION_KEY, stepperLayout.currentStepPosition) outState.putString(DATA, data) super.onSaveInstanceState(outState) } override fun onBackPressed() { val currentStepPosition = stepperLayout.currentStepPosition if (currentStepPosition > 0) { stepperLayout.onBackClicked() } else { finish() } } override fun saveData(data: String?) { this.data = data } override fun getData(): String? { return data } } 

Administrador de datos

 interface DataManager { fun saveData(data: String?) fun getData(): String? }