-1

I created an activity with five spinners, one button and textview. I want to set a text, when I click on the button, depending of the spinner choosing.

Thats my .xml code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".Deutschland.Masskonfigurator">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar">

    </include>

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:visibility="gone">

    </ListView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/listView"
        android:layout_above="@id/bottom_nav">

    <TextView
        android:id="@+id/masskonfigurator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="false"
        android:layout_centerVertical="false"
        android:layout_marginTop="20dp"
        android:fontFamily="@font/lato_light"
        android:gravity="center_horizontal"
        android:text="Maßkonfigurator"
        android:textSize="20sp"
        android:layout_marginBottom="20dp"/>


    <LinearLayout
        android:id="@+id/ll_spinners_area"
        android:layout_below="@id/masskonfigurator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:orientation="vertical">


    <!-- Start Country Germany-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:gravity="center_vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/wandart"
                android:textSize="14sp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="right|center_vertical">

                <androidx.appcompat.widget.AppCompatSpinner
                    android:id="@+id/spinner_wandart"
                    style="@style/spinner_style_ausgangsmass"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:foregroundTint="@color/ecd_blau"
                    android:gravity="center_vertical"
                    android:spinnerMode="dropdown"/>


            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:gravity="center_vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/fwst"
                android:textSize="14sp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="right|center_vertical">

                <androidx.appcompat.widget.AppCompatSpinner
                    android:id="@+id/spinner_fertigwandstaerke"
                    style="@style/spinner_style_ausgangsmass"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:foregroundTint="@color/ecd_blau"
                    android:gravity="center_vertical" />


            </LinearLayout>

        </LinearLayout>


        <LinearLayout
        android:id="@+id/ll_germany"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:focusable="true"
        android:orientation="horizontal"
        tools:ignore="UseCompoundDrawables"
        android:gravity="center_vertical"
        android:layout_gravity="center_vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center_vertical">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:text="@string/ausgangsmass">
        </TextView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="right|center_vertical">

        <androidx.appcompat.widget.AppCompatSpinner
            android:id="@+id/spinner_ausgangsmass"
            style="@style/spinner_style_ausgangsmass"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:foregroundTint="@color/ecd_blau"
            android:gravity="center_vertical" />

</LinearLayout>
        </LinearLayout>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:layout_marginTop="10dp">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:text="@string/breite">
        </TextView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="right|center_vertical">

            <androidx.appcompat.widget.AppCompatSpinner
                android:id="@+id/spinner_breite"
                style="@style/spinner_style_ausgangsmass"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:foregroundTint="@color/ecd_blau"
                android:gravity="center_vertical" />

        </LinearLayout>
    </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:gravity="center_vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/höhe"
                android:textSize="14sp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="right|center_vertical">

                <androidx.appcompat.widget.AppCompatSpinner
                    android:id="@+id/spinner_hoehe"
                    style="@style/spinner_style_ausgangsmass"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:foregroundTint="@color/ecd_blau"
                    android:gravity="center_vertical" />


            </LinearLayout>
        </LinearLayout>
    </LinearLayout>


        <LinearLayout
            android:layout_below="@+id/ll_spinners_area"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center_vertical"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="30dp">

            <Button
                android:id="@+id/btn_bestaetigen"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_round"
                android:padding="20dp"
                android:text="Auswahl bestätigen"
                android:textColor="@color/white"
                android:onClick="onButtonClick">
            </Button>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:orientation="horizontal"
                android:gravity="center_vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/art_nr"
        android:textSize="14sp"/>

        <TextView
            android:id="@+id/tv_artnr"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:foregroundTint="@color/ecd_blau"
            android:gravity="right"
            android:textStyle="bold"/>

                </LinearLayout>
            </LinearLayout>


    </RelativeLayout>


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:itemIconTint="@color/ecd_blau"
        app:itemTextColor="@color/ecd_blau"
        app:menu="@menu/bottom_navigation"/>

</RelativeLayout>

And thats my on click Listener:

Button btnBestaetigen = (Button)findViewById(R.id.btn_bestaetigen);

        btnBestaetigen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (    spinnerWandart.getSelectedItem().toString() == "Trockenbau" &&
                        spinnerFertigwandstaerke.getSelectedItem().toString() == "100 mm" ||
                        spinnerFertigwandstaerke.getSelectedItem().toString() == "125 mm" &&
                        spinnerAusgangsmass.getSelectedItem().toString() == "Türblattmaß" &&
                        spinnerBreite.getSelectedItem().toString() == "610 mm" &&
                        spinnerHoehe.getSelectedItem().toString() == "2110 mm") {
                    tvArtNr.setText("EKID610SB");

                } if (    spinnerWandart.getSelectedItem().toString() == "Trockenbau" &&
                        spinnerFertigwandstaerke.getSelectedItem().toString() == "100 mm" ||
                        spinnerFertigwandstaerke.getSelectedItem().toString() == "125 mm" &&
                        spinnerAusgangsmass.getSelectedItem().toString() == "Türblattmaß" &&
                        spinnerBreite.getSelectedItem().toString() == "610 mm" &&
                        spinnerHoehe.getSelectedItem().toString() == "1985 mm") {
                        tvArtNr.setText("EKID610SA");

                } else {
                    tvArtNr.setText("");
                }

            }});

Unfortunately it doesn´t work with this code. Also doesn't work, when I use for example .equals("Trockenbau") instead == "Trockenbau"

May one of you can help me :-)

Please excuse my bad english :D

Best regards, Daniel

Daniel
  • 1
  • 2

1 Answers1

0

Solved it :-) Had to set the same spinners in seperate bracket in the if statement. Then the "&&" an "||" arguments worked :-) Also had to use .equals instead "=="

Daniel
  • 1
  • 2