步进器中出错

时间:2017-10-22 17:02:48

标签: java android android-studio material-design

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.}

在调试时,控件不会转到createStep方法StepFragmentSample.java

mainActivity.java调试时,控件转到MyStepAdapter.java方法,然后转到MyStepperAdapter()方法,然后转到getCount()方法,但转到createStep()。为什么?请帮我。它没有任何例外。该应用显示“不幸停止”。

0 个答案:

没有答案