-1

Main activity looks like this:

package net.androidbootcamp.twitterstockcalculator;

import android.content.Intent;
import android.icu.text.DecimalFormat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;

import static net.androidbootcamp.twitterstockcalculator.R.id.btnCost;
import static net.androidbootcamp.twitterstockcalculator.R.id.txtResult;


public class MainActivity extends AppCompatActivity {

double costPerShare = 23.01;
int numberOfShares;
double totalCost;
//String one = "Cost for the Twitter Stock:";
//String two = ".";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final EditText number = (EditText)findViewById(R.id.txtNumber);
    Button button = (Button) findViewById(btnCost);

    button.setOnClickListener(new View.OnClickListener() {
       // final TextView result = ((TextView)findViewById(txtResult));
        @Override
        public void onClick(View v) {
            startActivity(new Intent(MainActivity.this,                                                              TotalSharePrice.class));
            numberOfShares = Integer.parseInt(number.getText().toString());
            totalCost = costPerShare * numberOfShares;
            DecimalFormat currency = new DecimalFormat("$###.##");
           // final TextView result = ((TextView)findViewById(txtResult));
          //  result.setText("Cost to buy Twitter Stock: $" +    currency.format(totalCost));




  *the second activity looks like this:


   package net.androidbootcamp.twitterstockcalculator;

   import android.content.Intent;
   import android.support.v7.app.AppCompatActivity;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.Button;
   import android.widget.TextView;

   import static net.androidbootcamp.twitterstockcalculator.R.id.btnCost;
   import static net.androidbootcamp.twitterstockcalculator.R.id.txtResult;


   public class TotalSharePrice extends AppCompatActivity {
   //String groupChoice;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_total_share_price);

    final TextView result = ((TextView)findViewById(R.id.txtResult));
    result.setText("Cost to buy Twitter Stock: $" + result );

How can I view the calculated result on the next screen?

I am doing a stock calculator and it just won't show the calculated result.

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • Note [we discourage requests for urgency](http://meta.stackoverflow.com/q/326569), and even more so in the title, where they are a form of question vandalism. Please refrain from adding this to your future posts, thanks. – halfer Oct 01 '16 at 22:22

1 Answers1

1

You need to pass that data to the second activity with your intent. See this answer.

Community
  • 1
  • 1
Stephen Paul
  • 37,253
  • 15
  • 92
  • 74