所以我有三个活动。如果所有输入都已填写,则一个用于接受来自用户的输入,然后一个下一个按钮移至第二个活动。

第二个活动可用于接受和更新第二个类中用于执行计算的一些已经定义的值,保存按钮用于保存新值,完成按钮用于执行计算并在上一个活动中显示结果。

输入后单击“保存”按钮时,每次决定使用一组新值时,如何更新第二个活动/类?

第一次活动

<EditText
    android:id="@+id/first_number"
    android:layout_width="304dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:background="@drawable/edittext_bg"
    android:ems="10"
    android:hint="Enter first Number"
    android:inputType="number"
    android:paddingStart="20dp"
    android:paddingEnd="10dp"
    android:paddingLeft="20dp"
    android:paddingTop="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:textSize="14sp" />

<EditText
    android:id="@+id/second_number"
    android:layout_width="304dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:background="@drawable/edittext_bg"
    android:ems="10"
    android:hint="Enter second Number"
    android:inputType="number"
    android:paddingStart="20dp"
    android:paddingEnd="10dp"/>

<EditText
    android:id="@+id/third_number"
    android:layout_width="304dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:background="@drawable/edittext_bg"
    android:ems="10"
    android:hint="Enter second Number"
    android:inputType="number"
    android:paddingStart="20dp"
    android:paddingEnd="10dp"/>

<Button
    android:id="@+id/btn_next"
    android:layout_width="145dp"
    android:layout_height="49dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/curved_button"
    android:paddingStart="5dp"
    android:paddingEnd="19dp"
    android:paddingRight="10dp"
    android:paddingLeft="2dp"
    android:drawableLeft="@drawable/add_button_image"
    android:text="@string/Next"
    android:textAllCaps="false"
    android:textColor="@android:color/background_light"
    android:typeface="serif"
    app:layout_constraintEnd_toEndOf="parent" />


SECOND ACTIVITY
<EditText
    android:id="@+id/contingencyFee"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="30dp"
    android:background="@color/pageColor"
    android:clickable="false"
    android:cursorVisible="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:hint="@string/contingency"
    android:inputType="none"
    android:textSize="16sp" />

<EditText
    android:id="@+id/projectManagement"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="30dp"
    android:background="@color/pageColor"
    android:clickable="false"
    android:cursorVisible="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:hint="@string/projectFee"
    android:inputType="none"
    android:textSize="16sp" />

<EditText
    android:id="@+id/externalWorks"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="30dp"
    android:background="@color/pageColor"
    android:clickable="false"
    android:cursorVisible="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:hint="@string/externalWorks"
    android:inputType="none"
    android:textSize="16sp" />

<Button
    android:id="@+id/save_button"
    android:layout_width="wrap_content"
    android:layout_height="38dp"
    android:layout_marginStart="120dp"
    android:layout_marginLeft="120dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="52dp"
    android:onClick="saveButton"
    android:background="@drawable/save_button"
    android:text="@string/inputVariableSaveButton"
    android:textColor="@android:color/background_light"
    app:layout_constraintBottom_toTopOf="@+id/textView16"
    app:layout_constraintEnd_toStartOf="@+id/proceedBtn"
    app:layout_constraintHorizontal_bias="0.464"
    app:layout_constraintTop_toBottomOf="@+id/scrollView3"
    app:layout_constraintVertical_bias="0.483" />

<Button
    android:id="@+id/proceed_button"
    android:layout_width="116dp"
    android:layout_height="32dp"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="52dp"
    android:onClick="proceed"
    android:text="@string/defaultVariable"
    android:textAllCaps="false"
    android:textColor="@android:color/background_light"
    android:textSize="18sp"
    app:layout_constraintBottom_toTopOf="@+id/textView16"
    app:layout_constraintEnd_toEndOf="parent"

FIRST CLASS

btn_next.setOnClickListener(new View.OnClickListener(){
        @RequiresApi(api = Build.VERSION_CODES.N)
        public void onClick(View v){
            try{

// **** VALUES FROM THE FIRST ACTIVITY

                double first_number =
Double.valueOf(first_number.getText().toString());
                double firstNumberTotal = first_number* /*
(250*70000)*/  17500000;

                double second_number =
Double.valueOf(second_number.getText().toString());
                double secondNumberTotal = second_number * /*
(214*70000)*/ 14980000;

                double third_number =
Double.valueOf(third_number.getText().toString());
                double thirdNumberTotal = third_number * /*
(140*70000)*/ 9800000;

            }catch (Exception ex){
                return;
            }
        }
    });


 SECOND CLASS
 save_button.setOnClickListener(new View.OnClickListener(){
        @RequiresApi(api = Build.VERSION_CODES.N)
        public void onClick(View v){
            try{

                // VALUES FROM SECOND ACTIVITY
        double contingencyFee =
        Double.valueOf(contingencyFeet.getText().toString());
                double contingencyTotal = contingencyFee *
        1.015; /*UPDATE THIS WITH NEW VALUE*/


      double projectManagement =
      Double.valueOf(projectManagement.getText().toString());
      double totalProjectCost = projectManagemen *
      1.2; /*UPDATE THIS WITH NEW VALUE*/

      double externalWorks =
      Double.valueOf(externalWorks.getText().toString());
                double externalWorksCost = externalWorks *
      1.15; /*UPDATE THIS WITH NEW VALUE*/

            }catch (Exception ex){
                return;
            }
        }
    });

最佳答案

单击按钮中的“首次活动”

intent = new Intent(FirstActivity.this, SecondActivity.class);
                    intent.putExtra("firstno", String.valueOf(firstnumber));
                    intent.putExtra("secondno", String.valueOf(secondnumber));
                    intent.putExtra("thirdno", String.valueOf(thirdnumber));
                    startActivity(intent);

负载第二活动
String firstNo, SecondNo, ThirdNo;
 firstNo = getIntent().getExtras().getString("firstno");
 SecondNo = getIntent().getExtras().getString("secondno");
 ThirdNo = getIntent().getExtras().getString("thirdno");

编辑内容
Double firstNo, SecondNo, ThirdNo;
firstNo = Double.parseDouble(getIntent().getExtras().getString("firstno"));
SecondNo = Double.parseDouble(getIntent().getExtras().getString("secondno"));
ThirdNo = Double.parseDouble(getIntent().getExtras().getString("thirdno"));

textView.setText(String.valueOf(firstNo + SecondNo + ThirdNo));

07-26 03:49