The textbox of the current Activity is not updated when another item is selected in the RadioButton of the previous Activity. Android/Java

  android, android-activity, class, java, methods

The application should count the moments of inertia and moments of resistance of the profiles, and output the value of the selected profile in the TextView.
Application work:

  1. The user enters the value of loads, deflection, length
  2. Selects the required profile via radoiButton
  3. Clicks on the "Execute calculation" button
  4. The application reads and displays the value of the selected profile in the TextView
    At the first launch, the application works correctly and everything is displayed. But when you exit to the previous activity to change the profile selection via radoiButton, the value of the text field does not change and remains the same as in the previous selection. Only restarting the entire application helps.
    It turns out that to change the cross-section, you need to completely terminate the application each time and re-enter the data.

data input activity1

public class StBalkaSchema1CopyActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
 
    public EditText loadEditText;
    public EditText lengthEditText;
    private Spinner deflectionSpinner;
    private ArrayList deflectionSpinnerArrayList;
    private ArrayAdapter deflectionSpinnerAdapter;
 
    private String valueDeflection;
 
    private RadioGroup radioGroupShveller;
    private RadioGroup radioGroupShvellerX2;
    private RadioGroup radioGroupDvutavr;
 
    private int valueSelectedGost;
 
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_st_balka_schema1_copy);
 
        setTitle("Введите нагрузку и пролет балки");
 
        loadEditText = (EditText) findViewById(R.id.loadEditText);
        lengthEditText = (EditText) findViewById(R.id.lengthEditText);
 
        radioGroupShveller = findViewById(R.id.radioGroupShveller);
        radioGroupShvellerX2 = findViewById(R.id.radioGroupShvellerX2);
        radioGroupDvutavr = findViewById(R.id.radioGroupDvutavr);
 
        createDeflectionSpinner();
 
}
 
    public void createDeflectionSpinner(){
        deflectionSpinner = findViewById(R.id.deflectionSpinner);
        deflectionSpinner.setOnItemSelectedListener(this);
        deflectionSpinnerArrayList = new ArrayList();
 
        deflectionSpinnerArrayList.add(120);
        deflectionSpinnerArrayList.add(150);
        deflectionSpinnerArrayList.add(200);
        deflectionSpinnerArrayList.add(250);
        deflectionSpinnerArrayList.add(300);
 
        deflectionSpinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, deflectionSpinnerArrayList);
        deflectionSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        deflectionSpinner.setAdapter(deflectionSpinnerAdapter);
    }
 
    public void shvellerOnClick(View view) {
 
        radioGroupShveller.removeAllViews();
 
        RadioButton shvellerYRadioButton = new RadioButton(this);
        RadioButton shvellerPRadioButton = new RadioButton(this);
 
        shvellerYRadioButton.setText(R.string.shveller_Y);
        shvellerPRadioButton.setText(R.string.shveller_P);
 
        radioGroupShveller.addView(shvellerYRadioButton);
        radioGroupShveller.addView(shvellerPRadioButton);
 
        shvellerPRadioButton.setOnClickListener(radioButtonClickListener);
        shvellerYRadioButton.setOnClickListener(radioButtonClickListener);
 
        shvellerYRadioButton.setId(R.id.idShvellerYRadioButton);
        shvellerPRadioButton.setId(R.id.idShvellerPRadioButton);
 
        radioGroupShvellerX2.removeAllViews();
        radioGroupDvutavr.removeAllViews();
 
        radioGroupShvellerX2.clearCheck();
        radioGroupDvutavr.clearCheck();
 
    }
 
    public void dvaShvelleraOnClick(View view) {
 
        radioGroupShvellerX2.removeAllViews();
 
        RadioButton shvellerYX2RadioButton = new RadioButton(this);
        RadioButton shvellerPX2RadioButton = new RadioButton(this);
 
        shvellerYX2RadioButton.setText(R.string.shveller_Y_x2);
        shvellerPX2RadioButton.setText(R.string.shveller_P_x2);
 
        radioGroupShvellerX2.addView(shvellerYX2RadioButton);
        radioGroupShvellerX2.addView(shvellerPX2RadioButton);
 
        shvellerYX2RadioButton.setOnClickListener(radioButtonClickListener);
        shvellerPX2RadioButton.setOnClickListener(radioButtonClickListener);
 
        shvellerYX2RadioButton.setId(R.id.idShvellerYX2RadioButton);
        shvellerPX2RadioButton.setId(R.id.idShvellerPX2RadioButton);
 
        radioGroupShveller.removeAllViews();
        radioGroupDvutavr.removeAllViews();
 
        radioGroupShvellerX2.clearCheck();
        radioGroupDvutavr.clearCheck();
 
    }
 
    public void dvutavrOnClick(View view) {
 
        radioGroupDvutavr.removeAllViews();
 
        RadioButton dvutavrBRadioButton = new RadioButton(this);
        RadioButton dvutavrKRadioButton = new RadioButton(this);
 
        dvutavrBRadioButton.setText(R.string.dvutavr_B);
        dvutavrKRadioButton.setText(R.string.dvutavr_K);
 
        radioGroupDvutavr.addView(dvutavrBRadioButton);
        radioGroupDvutavr.addView(dvutavrKRadioButton);
 
        dvutavrBRadioButton.setOnClickListener(radioButtonClickListener);
        dvutavrKRadioButton.setOnClickListener(radioButtonClickListener);
 
        dvutavrBRadioButton.setId(R.id.idDvutavBRadioButton);
        dvutavrKRadioButton.setId(R.id.idDvutavKRadioButton);
 
        radioGroupShveller.removeAllViews();
        radioGroupShvellerX2.removeAllViews();
 
        radioGroupShvellerX2.clearCheck();
        radioGroupShveller.clearCheck();
 
    }
 
 
    View.OnClickListener radioButtonClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RadioButton rb = (RadioButton)v;
            switch (rb.getId()) {
                case R.id.idShvellerYRadioButton:
                    valueSelectedGost = 0;
                    break;
                case R.id.idShvellerPRadioButton:
                    valueSelectedGost = 1;
                    break;
                case R.id.idShvellerYX2RadioButton:
                    valueSelectedGost = 10;
                    break;
                case R.id.idShvellerPX2RadioButton:
                    valueSelectedGost = 11;
                    break;
                case R.id.idDvutavBRadioButton:
                    valueSelectedGost = 20;
                    break;
                case R.id.idDvutavKRadioButton:
                    valueSelectedGost = 21;
                    break;
            }
        }
    };
 
 
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        valueDeflection = deflectionSpinner.getSelectedItem().toString();
 
    }
 
    @Override
    public void onNothingSelected(AdapterView<?> parent) {
 
    }
 
 
    public void vypolnitRaschetOnClick(View view) {
 
        int putGost = valueSelectedGost;
 
        Intent performCalculationIntent = new Intent(StBalkaSchema1CopyActivity.this, StBalkaShema1RaschetCopyActivity.class);
 
        String putLoad = loadEditText.getText().toString();
        performCalculationIntent.putExtra("load", putLoad);
 
        String putLength = lengthEditText.getText().toString();
        performCalculationIntent.putExtra("length", putLength);
 
        String putDeflection = deflectionSpinner.getSelectedItem().toString();
        performCalculationIntent.putExtra("deflection", putDeflection);
 
        performCalculationIntent.putExtra("gostInt", putGost);
 
        startActivity(performCalculationIntent);
    }

Activity2 calculation

public class StBalkaShema1RaschetCopyActivity extends AppCompatActivity{
 
    private ImageView selectedProfileImageView;
    private TextView loadTextView;
    private TextView lengthTextView;
    private TextView deflectionTextView;
    private TextView formulaQmaxTextView;
 
    private TextView formulaMmaxTextView;
    private TextView formulaWtrTextView;
    private TextView formulaItrTextView;
    private TextView epuraQpolozhZnachTextView;
    private TextView epuraQotricZnachTextView;
    private TextView epuraMTextView;
    private TextView selectedProfileTextView;
    private TextView infoSelectedProfileTextView;
 
    private TextView textViewGostInt;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_st_balka_shema1_raschet_copy);
        setTitle("Решение");
 
        Intent intent = getIntent();
        String getLoad = intent.getStringExtra("load");
        String getLength = intent.getStringExtra("length");
        String getDeflection = intent.getStringExtra("deflection");
        int getGostInt = intent.getIntExtra("gostInt",0);
 
 
        selectedProfileImageView = (ImageView) findViewById(R.id.selectedProfileImegeView);
        selectedProfileTextView = (TextView) findViewById(R.id.selectedProfileTextView);
 
        loadTextView = (TextView) findViewById(R.id.loadTextView);
        lengthTextView = (TextView) findViewById(R.id.lengthTextView);
        deflectionTextView = (TextView) findViewById(R.id.deflectionTextView);
        formulaQmaxTextView = (TextView) findViewById(R.id.formulaQmaxTextView);
 
        formulaMmaxTextView = (TextView) findViewById(R.id.formulaMmaxTextView);
        formulaWtrTextView = (TextView) findViewById(R.id.formulaWtrTextView);
        formulaItrTextView = (TextView) findViewById(R.id.formulaItrTextView);
        epuraQpolozhZnachTextView = (TextView) findViewById(R.id.epuraQpolozhZnachTextView);
        epuraQotricZnachTextView = (TextView) findViewById(R.id.epuraQotricZnachTextView);
        epuraMTextView = (TextView) findViewById(R.id.epuraMTextView);
 
        infoSelectedProfileTextView = (TextView) findViewById(R.id.infoSelectionProfileTextView);
 
        textViewGostInt = (TextView) findViewById(R.id.textViewGostInt);
 
 
 
        textViewGostInt.setText("" + getGostInt);
 
        loadTextView.setText(getLoad);
        lengthTextView.setText(getLength);
        deflectionTextView.setText(getDeflection);
 
 
        double loadToFormula = Double.parseDouble(loadTextView.getText().toString());
        double lengthToFormula = Double.parseDouble(lengthTextView.getText().toString());
        double deflectionToFormula = Double.parseDouble(deflectionTextView.getText().toString());
 
        double lengthMToFormula = lengthToFormula / 1000;
        double resultQmax = loadToFormula / 1000 * lengthMToFormula /2;
        int degreeTwo = 2;   //для числа в степени 2
        int degreeFive = 5;      //для числа в степени 5
        int degreeSix = 6;    //для числа в степени 5
        double resultMmax = loadToFormula / 1000 * Math.pow(lengthMToFormula, 2) /8;
        double resultWtr = resultMmax * 100 / (1.12*2.1);
        double resultItr = resultMmax * Math.pow(10, 5) * lengthMToFormula * Math.pow(10, 2) * deflectionToFormula / (10 * 2.1 * Math.pow(10, 6));
        String resultQmaxOkr = String.format("%.2f",resultQmax);
        String resultMmaxOkr = String.format("%.2f",resultMmax);
        String resultWtrOkr = String.format("%.2f",resultWtr);
        String resultItrOkr = String.format("%.2f",resultItr);
 
 
        if (getGostInt >= 0 & getGostInt <= 9){
            selectedProfileImageView.setImageResource(R.drawable.shveller);
            if (getGostInt == 0){
                ShvellerU_GOST_8240_89.addShvellerU();
                infoSelectedProfileTextView.setText(ShvellerU_GOST_8240_89.getClosestInertiaResistance(resultItr, resultWtr));
                selectedProfileTextView.setText(R.string.shveller_Y);
            } else if (getGostInt == 1){
                ShvellerP_GOST_8240_89.addShvellerP();
                infoSelectedProfileTextView.setText(ShvellerP_GOST_8240_89.getClosestInertiaResistance(resultItr, resultWtr));
                selectedProfileTextView.setText(R.string.shveller_P);
            }else {
                infoSelectedProfileTextView.setText("Профиль не выбран");
                selectedProfileTextView.setText("Профиль не выбран");
            }
 
        } else if (getGostInt >= 10 & getGostInt <= 19){
            selectedProfileImageView.setImageResource(R.drawable.dva_shvellera);
            if(getGostInt == 10){
                ShvellerUx2_GOST_8240_89.addShvellerUx2();
                infoSelectedProfileTextView.setText(ShvellerUx2_GOST_8240_89.getClosestInertiaResistance(resultItr, resultWtr));
                selectedProfileTextView.setText(R.string.shveller_Y_x2);
            } else if (getGostInt == 11){
                ShvellerPx2_GOST_8240_89.addShvellerPx2();
                infoSelectedProfileTextView.setText(ShvellerPx2_GOST_8240_89.getClosestInertiaResistance(resultItr, resultWtr));
                selectedProfileTextView.setText(R.string.shveller_P_x2);
            } else {
                infoSelectedProfileTextView.setText("Профиль не выбран");
                selectedProfileTextView.setText("Профиль не выбран");
            }
 
        } else if (getGostInt >= 20 & getGostInt <= 29) {
            selectedProfileImageView.setImageResource(R.drawable.dvutavr);
            if (getGostInt == 20){
                DvutavrB_Gost26020_83.addDvutavrB();
                infoSelectedProfileTextView.setText(DvutavrB_Gost26020_83.getClosestInertiaResistance(resultItr, resultWtr));
                selectedProfileTextView.setText(R.string.dvutavr_B);
            } else if (getGostInt == 21){
                DvutavrK_Gost26020_83.addDvutavrK();
                infoSelectedProfileTextView.setText(DvutavrK_Gost26020_83.getClosestInertiaResistance(resultItr, resultWtr));
                selectedProfileTextView.setText(R.string.dvutavr_K);
            }else {
                infoSelectedProfileTextView.setText("Профиль не выбран");
                selectedProfileTextView.setText("Профиль не выбран");
            }
        }
 
 
 
        epuraQpolozhZnachTextView.setText(resultQmaxOkr + "т");
        epuraQotricZnachTextView.setText("-"+ resultQmaxOkr + "т");
        epuraMTextView.setText("Mmax =" + resultMmaxOkr + "т" + "u00D7" +"2");
 
        String formulaQmax = "Qₘₐₓ = (q /1000 " + "u00D7" + " L) / 2 ="
                + System.lineSeparator() + "(" + loadToFormula +"/1000 " + "u00D7" + lengthMToFormula + ") / 2 =" + resultQmaxOkr + "т";
        formulaQmaxTextView.setText(formulaQmax);
 
        String formulaMmax = "Mₘₐₓ = (q /1000" + "u00D7" + "L" + "²" + " ) / 8 ="
                + System.lineSeparator() + "(" + loadToFormula +"/1000 " + "u00D7" + lengthMToFormula + "²" + " ) / 8 =" + resultMmaxOkr + "т" + "u00D7" +"2";
        formulaMmaxTextView.setText(formulaMmax);
 
        String formulaWtr = "Wₜᵣ = Mₘₐₓ" + "u00D7" + "100" + " / (1.12" + "u00D7" + " R) ="
                + System.lineSeparator()  + resultMmaxOkr + "u00D7" + "100" + " / (1.12" + "u00D7" + " 2.1) = " + resultWtrOkr + "см³";
        formulaWtrTextView.setText(formulaWtr);
 
        String formulaItr = "Tₜᵣ = Mₘₐₓ" + "u00D7" + "10⁵" + "u00D7" + "L" + "u00D7" + "10²" + "u00D7" + "filt" + "/" + "(10" +
                "u00D7" + "E) = "
                + System.lineSeparator()  + resultMmaxOkr + "u00D7" + "10⁵" + "u00D7" + lengthMToFormula + "u00D7" + "10²" + "u00D7" + deflectionToFormula + "/" + "(10" +
                "u00D7" + "2.1" + "u00D7" + "10⁶) = " + resultItrOkr + "см⁴";
        formulaItrTextView.setText(formulaItr);
    }
 
}

Profile adding method

public class ShvellerU_GOST_8240_89 extends Shveller {
 
    public ShvellerU_GOST_8240_89(String name, double momentSoprotivleniya, double momentInertsii, double massa) {
        super(name, momentSoprotivleniya, momentInertsii, massa);
    }
 
    public static void addShvellerU() {
        ShvellerU_GOST_8240_89 shveller5U = new ShvellerU_GOST_8240_89("5У", 9.1,22.8,4.84);
        shveller5U.putIn(shveller5U);
 
        ShvellerU_GOST_8240_89 shveller6_5U = new ShvellerU_GOST_8240_89("6,5У", 15,48.6,5.9);
        shveller6_5U.putIn(shveller6_5U);
 
        ShvellerU_GOST_8240_89 shveller8U = new ShvellerU_GOST_8240_89("8У", 22.4,89.4,7.05);
        shveller8U.putIn(shveller8U);
 
        ShvellerU_GOST_8240_89 shveller10U = new ShvellerU_GOST_8240_89("10У", 34.8,174.0,8.59);
        shveller10U.putIn(shveller10U);
 
    }
 
}

The error will most likely occur in this block activity2 calculation.

if (getGostInt == 0){
                ShvellerU_GOST_8240_89.addShvellerU();     
 infoSelectedProfileTextView.setText(ShvellerU_GOST_8240_89.getClosestInertiaResistance(resultItr, resultWtr));
selectedProfileTextView.setText(R.string.shveller_Y);

I think that this is due to the fact that when objects are added through the addShvellerU () method, they remain in memory and when a different section is selected, the addDvutavrK () method cannot overwrite another. How to solve this problem?

Source: Android Questions

LEAVE A COMMENT