-1
I made the App to add two numbers, but when I put a start screen with only one button to call the sum screen, the calculations of the sum screen are inactive, how to solve? Thank you
Screen Mainactivity.java
package br.com.frutasalmeidasantos.www.testefinal;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void chamasolucao (View v) { setContentView(R.layout.activity_solucao); }
}
Solucao.java
package br.com.frutasalmeidasantos.www.testefinal;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Solucao extends AppCompatActivity {
    EditText campo1;
    EditText campo2;
    Button btcalc;
    TextView resposta;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_solucao);
        campo1 = (EditText) findViewById(R.id.campo1);
        campo2 = (EditText) findViewById(R.id.campo2);
        btcalc = (Button) findViewById(R.id.btcalc);
        resposta = (TextView) findViewById(R.id.resposta);
        btcalc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String scampo1 = campo1.getText().toString();
                String scampo2 = campo2.getText().toString();
                if (scampo1.isEmpty() || scampo2.isEmpty()){
                    Toast.makeText(Solucao.this, "", Toast.LENGTH_SHORT).show();
                    return;
                }
                int ncampo1 = Integer.parseInt(scampo1);
                int ncampo2 = Integer.parseInt(scampo2);
                int nresposta = ncampo1 + ncampo2;
                resposta.setText(""+ncampo1+ "+" +ncampo2+ "=" +nresposta);
            }
        });
    }
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.frutasalmeidasantos.www.testefinal">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Solucao"></activity>
    </application>
</manifest>
Change the method
chamasolucao()forpublic void chamasolucao (View v) { startActivity(new Intent(this, Solucao.class)); }– ramaral
Thanks @ramaral, it worked!
– Gilberto Almeida