添加垂直步进库时显示错误

时间:2017-08-07 17:56:22

标签: android stepper

我想在android中实现Vertical Stepper Library。但出了点问题,它显示错误: 由java.lang.IllegalArgumentException引起:无法将空子视图添加到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>

1 个答案:

答案 0 :(得分: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文件,然后您可能不会遇到此问题。