OnClickListinger, missing statement?

  android, javascript, onclicklistener

I have a problem with a code..

I got 2 Switches, 2 Textviews, and 2 Spinners, tied together in a "OnClickListinger".

Like so:

Java

swaxles.setOnClickListener(v -> {
            roadwheels.setVisibility(View.GONE);
            roadwheelsspinner.setVisibility(View.GONE);
            axles.setVisibility(View.VISIBLE);
            axlesspinner.setVisibility(View.VISIBLE);
            swroadwheels.setChecked(!swroadwheels.isChecked());
        });

        swroadwheels.setOnClickListener(v -> {
            roadwheels.setVisibility(View.VISIBLE);
            roadwheelsspinner.setVisibility(View.VISIBLE);
            axles.setVisibility(View.GONE);
            axlesspinner.setVisibility(View.GONE);
            swaxles.setChecked(!swaxles.isChecked());
        });

XML

    <Switch
        android:id="@+id/swroadwheels"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:checked="true"
        android:minHeight="48dp"
        android:text="@string/textroadwheels"
        android:textColor="#000080"
        android:textSize="20sp"
        app:layout_constraintBottom_toTopOf="@+id/view2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view"
        tools:ignore="UseSwitchCompatOrMaterialXml" />

    <Switch
        android:id="@+id/swaxles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="60dp"
        android:layout_marginLeft="60dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:minHeight="48dp"
        android:text="@string/textaxles"
        android:textColor="#000080"
        android:textSize="20sp"
        app:layout_constraintBottom_toTopOf="@+id/view2"
        app:layout_constraintStart_toEndOf="@+id/swroadwheels"
        app:layout_constraintTop_toBottomOf="@+id/view"
        tools:ignore="UseSwitchCompatOrMaterialXml" />

    <TextView
        android:id="@+id/roadwheels"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:text="@string/textof_road_wheels"
        android:textColor="#000080"
        android:textSize="20sp"
        android:visibility="visible"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view2" />

    <TextView
        android:id="@+id/axles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="16dp"
        android:text="@string/textof_axles"
        android:textColor="#000080"
        android:textSize="20sp"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view2" />

    <Spinner
        android:id="@+id/roadwheelsspinner"
        style="@style/spinner_style"
        android:layout_width="155dp"
        android:layout_height="28dp"
        android:visibility="visible"
        app:layout_constraintEnd_toEndOf="@+id/roadwheels"
        app:layout_constraintStart_toStartOf="@+id/roadwheels"
        app:layout_constraintTop_toBottomOf="@+id/roadwheels" />

    <Spinner
        android:id="@+id/axlesspinner"
        style="@style/spinner_style"
        android:layout_width="90dp"
        android:layout_height="28dp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="@+id/axles"
        app:layout_constraintStart_toStartOf="@+id/axles"
        app:layout_constraintTop_toBottomOf="@+id/axles" />

Just to make it easier to explain my problem:

Switch "swroadwheels" = Switch A

Switch "swaxles" = Switch B

Textview "roadwheels" = Text A

Textview "axles" = Text B

Spinner "roadwheelsspinner" = Spinner A

Spinner "axlesspinner" = Spinner B

Example:

Switch A is ON …. Switch B is OFF

If i turn OFF Switch A it will turn ON Switch B and vice versa…

Aswell if I turn ON Switch B it will make Text A and Spinner A GONE

and make Text B and Spinner B VISIBLE and vice versa…

BUT… if i turn OFF Switch B it will turn ON Switch A but it will not trigger the visibility of Text A/B and Spinner A/B..

I know why it doesn’t happen and that’s because it hasn’t been given any statement in what to do if I switch it off..

but my problem is: How do I come with that statement?

Do I need to implement if, else statement somehow or??

Source: Android Questions

LEAVE A COMMENT