Home » Android » Getting error in steppers

Getting error in steppers

Posted by: admin November 1, 2017 Leave a comment

Questions:

StepFragmentSample.java:

public class StepFragmentSample extends Fragment implements Step {
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.step, container, false);
        //initialize your UI
        return v;
    }

    public VerificationError verifyStep() {
        //return null if the user can go to the next step, create a new VerificationError instance otherwise
        return null;
    }

    @Override
    public void onSelected() {
        //update UI when selected
    }

    @Override
    public void onError(@NonNull VerificationError error) {
        //handle error inside of the fragment, e.g. show error on EditText
    }
}

MyStepAdapter.java:

public static class MyStepperAdapter extends AbstractFragmentStepAdapter {
    public MyStepperAdapter(FragmentManager fm, Context context) {
        super(fm, context);
    }

    @Override
    public Step createStep(int position) {
        final StepFragmentSample step = new StepFragmentSample();
        Bundle b = new Bundle();
        b.putInt(CURRENT_STEP_POSITION_KEY, position);
        step.setArguments(b);
        return step;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @NonNull
    @Override
    public StepViewModel getViewModel(@IntRange(from = 0) int position) {
        //Override this method to set Step title for the Tabs, not necessary for other stepper types
        return new StepViewModel.Builder(context)
            .setTitle(R.string.tab_title) //can be a CharSequence instead       
            .create();
    }
}

MainActivity.java:

public class StepperActivity extends AppCompatActivity {
    private StepperLayout mStepperLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mStepperLayout = (StepperLayout) findViewById(R.id.stepperLayout);
        mStepperLayout.setAdapter(new MyStepperAdapter(getSupportFragmentManager(), this));
    }

I have copied the above code from this link.}

While debugging, the control does not goes to createStep Method In StepFragmentSample.java

while debugging from mainActivity.java, the control goes to MyStepAdapter.java in that first MyStepperAdapter() method then to getCount() method but not to createStep(). why? please help me. and It does not giving any exception. The app shows “unfortunately stopped”.

Answers: