If condition based on another activity value

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 10

Apr 10, 2021, 1:55:54 PM via Website

Dear Team,

I am having three activities called (Activity1, Activity2 & Activity 3).

In my Activity1 I am having AutoCompleteTextView

<com.google.android.material.textfield.TextInputLayout
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
            android:id="@+id/model"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorEnabled="true"
            app:boxStrokeColor="#1976D2"
            app:hintTextColor="#1976D2"
            android:textColorHint="#78909C"
            app:endIconTint="#78909C"
            app:shapeAppearance="@style/Rounded"
            app:endIconMode="dropdown_menu">

            <AutoCompleteTextView
                android:id="@+id/auto"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="select plant Model"
                android:textSize="18dp"
                android:importantForAutofill="no"
                android:textColor="@color/black"
                android:padding="15dp"/>

        </com.google.android.material.textfield.TextInputLayout>

In Activity2 I am having TextInputEditText, AutoCompleteTextView & Button

 <com.google.android.material.textfield.TextInputLayout
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                android:id="@+id/maximium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:boxStrokeColor="#1976D2"
                app:shapeAppearance="@style/Rounded"
                app:errorEnabled="true">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/edit"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"
                    android:importantForAutofill="no"
                    android:inputType="number"
                    android:textColor="@color/black" />

            </com.google.android.material.textfield.TextInputLayout>

style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:id="@+id/interval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
android:layout_marginTop="10dp"
app:boxStrokeColor="#1976D2"
app:hintTextColor="#1976D2"
app:endIconTint="#78909C"
app:shapeAppearance="@style/Rounded"
app:endIconMode="dropdown_menu">

                <AutoCompleteTextView
                    android:id="@+id/select"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"
                    android:textSize="18dp"
                    android:importantForAutofill="no"
                    android:textColor="@color/black"
                    android:paddingLeft="15dp"/>

            </com.google.android.material.textfield.TextInputLayout>

android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:textAllCaps="false"
android:padding="5dp"
app:shapeAppearance="@style/Rounded"
android:backgroundTint="#1976D2"
android:textColor="@color/white"
android:text="Ascending Order"/>

And my Activity 3 having Textview.

<TextView
                android:id="@+id/text1"
                android:layout_width="300dp"
                android:layout_height="35dp"
                android:layout_weight="1"
                android:padding="5dp"
                android:textSize="18sp"
                android:textStyle="bold"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:textColor="@color/white"/>

My requirement is when I click the button from Activity2, my Activity3 text view should display the sum values of Activity2 TextInputEditText, AutoCompleteTextView.

If my Activity1 AutoCompleteTextView is selected "OK" then the Activity3 text view should display the sum values. otherwise, it should display "2".

I tried the following code on my Activity1

autocom1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            String value = autocom1.getText().toString();

            Intent i = new Intent(BasicDetails.this, AggreAscendingorder.class);
            Bundle b = new Bundle();
            b.putString("value", value);
            i.putExtras(b);
            startActivity(i);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

and I don't know exactly how to write further code on my other activities.

Can anyone help me with how to do this?

Reply
  • Forum posts: 19

Apr 11, 2021, 11:00:33 PM via Website

wonderful information

Helpful?
Reply