Passing parameters from an Activity to a calculation class

0

I would like you to help me in a situation that I am doing in my project, but that somehow the application stops clicking the calculate button.

I'll give you a simple example to know more or less of what I need. The user enters two numbers into a Data Entry Activity, these numbers go to a class (only to calculate, without Activity) and then return to a Result Activity.

I need you to show me exactly how you make this transition, what I did wrong, and so on. This is because in my project I have many more variables and a lot more accounts to be performed, and I will need two classes of calculations (because the calculations are different)

I thank you for your attention. I hope I have been clear and given a simple example for solution.

Data Entry Activity

    public class Entrada_Dados extends AppCompatActivity  implements View.OnClickListener{

    //Declarando variáveis
        public EditText txt_numero1;
        public EditText txt_numero2;

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

    //Relacionando variáveis com objetos
        txt_numero1=(EditText)findViewById(R.id.txt_numero1);
        txt_numero2= EditText)findViewById(R.id.txt_numero2);

    }

    public void onClick (View View) {

    //Transferindo parâmetros
        Intent it = new Intent(this, Calculo.class );

        it.putExtra("numero1", txt_numero1.getText().toString());
        it.putExtra("numero2", txt_numero2.getText().toString());

        startActivity(it);
        finish();
    }
}

Calculation class

 public class Calculo extends AppCompatActivity {

    //Declarando variáveis
    public double numero1;
    public double numero2;
    public double resultado;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String txt_numero1 = getIntent().getStringExtra("numero1"); //Recuperar na string
        numero1=Double.parseDouble(txt_numero1); //Passando para double

        String txt_numero2 = getIntent().getStringExtra("numero2"); //Recuperar na string
        numero2=Double.parseDouble(txt_numero2); //Passando para double

        startActivity(new Intent(this, Resultado.class));

    }

public double calculo_soma(){

        return resultado = numero1 + numero2;

    }

Result Activity

  public class Resultado extends AppCompatActivity implements View.OnClickListener{

    public TextView txt_resultado;

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

        txt_resultado= (TextView)findViewById(R.id.txt_resultado);

    }

    public void onClick (View v){

    //Chamando a classe
        Calculo Calculo = new Calculo ();

        double calculo_soma = Calculo.calculo_soma(); 
        String stg_resultado = Double.toString(calculo_soma);
        txt_resultado.setText(stg_resultado);

    }
}

** They asked me what error I was giving (remembering that the example I gave here is not my project, but the figure I'll add is the app I'm making **

    
asked by anonymous 19.01.2017 / 18:36

0 answers