简体   繁体   中英

Showing data in textView after going to next page

I am facing difficulties in showing data in textView after going to the next page
I am storing the return value in EMI variable but I am not able to print that value in the next page textview.

public class EmiCalculator  extends AppCompatActivity {

    public static double emical(double p,double r, double t)
    {
        double emi;

        r = r / (12 * 100); // one month interest
        t = t * 12; // one month period
        emi = (p * r * (double)Math.pow(1 + r, t)) / (double)(Math.pow(1 + r, t) - 1);

        return (emi);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.emi_calculator);

        EditText getText_1, getText_2, getText_3;

        getText_1 = (EditText) findViewById(R.id.emi_editText_1);
        getText_2 = (EditText) findViewById(R.id.emi_editText_2);
        getText_3 = (EditText) findViewById(R.id.emi_editText_3);

        Button calculateButton = (Button) findViewById(R.id.emi_calculate);
        calculateButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                double emi_edit_Text_01 = Double.parseDouble(getText_1.getText().toString());
                double emi_edit_Text_02 = Double.parseDouble(getText_2.getText().toString());
                double emi_edit_Text_03 = Double.parseDouble(getText_3.getText().toString());

               double emi = emical(emi_edit_Text_01, emi_edit_Text_02, emi_edit_Text_03);
               String str = String.valueOf(emi);

                TextView result = (TextView) findViewById(R.id.result_textView_3);
                result.setText(""+emi);
                Intent nextPage = new Intent(EmiCalculator.this,Result.class);
                startActivity(nextPage);
            }
        });
    }
}

you must use

Intent.putExtra

for send data to another activity.

in first activity:

 Intent nextPage = new Intent(EmiCalculator.this,Result.class);
 nextPage.putExtra("result",""+emi);
 startActivity(nextPage);

in second activity:

Intent intentResult=this.getIntent;
if(intentResult.hasExtra("result")){
    textview.setText(intent.getStringExtra("result"));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM