0

我想在 android 中实现 Vertical Stepper Library。但是出了点问题,它显示一个错误: Caused by java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_stepper);

    int colorPrimary = ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary);
    int colorPrimaryDark = ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark);
    String[] stepsTitles = getResources().getStringArray(R.array.steps_titles);

    // Finding the view
    verticalStepperForm = (VerticalStepperFormLayout) findViewById(R.id.vertical_stepper_form);

    // Setting up and initializing the form
    VerticalStepperFormLayout.Builder.newInstance(verticalStepperForm, stepsTitles,this, this)
            .primaryColor(colorPrimary)
            .primaryDarkColor(colorPrimaryDark)
            .displayBottomNavigation(true)
            .init();
}

Gradle 中添加的库:

compile 'com.ernestoyaquello.stepperform:vertical-stepper-form:0.9.9'

XML 文件如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".StepperExampleActivity">

<ernestoyaquello.com.verticalstepperform.VerticalStepperFormLayout
    android:id="@+id/vertical_stepper_form"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"/>

</RelativeLayout>
4

1 回答 1

1

很抱歉回复太晚了。我刚看到这个帖子。我不能评论这篇文章。

首先,您是否浏览了 ( https://github.com/ernestoyaquello/vertical-stepper-form ) 完整文档并遵循了所有步骤,例如实施VerticalStepperForm

如果是,那么您是否创建了一个视图并在 createStepContentView 中传递了它。

@Override
public View createStepContentView(int stepNumber) {
    View view = null;
    switch (stepNumber) {
        case 0:
            view = createNameStep();
            break;
        case 1:
            view = createEmailStep();
            break;
        case 2:
            view = createPhoneNumberStep();
            break;
    }
    return view;
}

private View createEmailStep() {
    // In this case we generate the view by inflating a XML file
    LayoutInflater inflater = LayoutInflater.from(getBaseContext());
    LinearLayout emailLayoutContent = (LinearLayout) inflater.inflate(R.layout.email_step_layout, null, false);
    email = (EditText) emailLayoutContent.findViewById(R.id.email);
    ...
    return emailLayoutContent;
}

R.layout.email_step_layout你必须创建这个 xml 文件,然后你可能不会遇到这个问题。

于 2018-03-27T09:37:05.257 回答