código activity formulário
package alura.com.br.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import alura.com.br.DAO.AlunoDAO;
import alura.com.br.R;
import alura.com.br.model.Aluno;
public class FormularioAlunoActivity extends AppCompatActivity {
public static final String TITLE = "Novo Aluno";
private EditText campoNome;
private EditText campoTelefone;
private EditText campoEmail;
private final AlunoDAO DAO = new AlunoDAO();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulario_aluno);
setTitle(TITLE);
inicializacaoDosCampos();
configuraBotaoSalvar();
}
private void configuraBotaoSalvar() {
Button botaoSalvar = findViewById(R.id.activity_formulario_aluno_salvar);
botaoSalvar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(FormularioAlunoActivity.this, "Salvo", Toast.LENGTH_SHORT).show();
Aluno alunoCriado = criaAluno(campoNome, campoTelefone, campoEmail);
salvar(alunoCriado);
startActivity(new Intent(FormularioAlunoActivity.this, ListaAlunosActivity.class));
}
});
}
private void inicializacaoDosCampos() {
campoNome = findViewById(R.id.activity_formulario_aluno_nome);
campoTelefone = findViewById(R.id.activity_formulario_aluno_telefone);
campoEmail = findViewById(R.id.activity_formulario_aluno_email);
}
private void salvar(Aluno aluno) {
DAO.salva(aluno);
}
private Aluno criaAluno(EditText campoNome, EditText campoTelefone, EditText campoEmail) {
String nome = this.campoNome.getText().toString();
String telefone = this.campoTelefone.getText().toString();
String email = this.campoEmail.getText().toString();
Aluno alunoCriado = new Aluno(nome, telefone, email);
return alunoCriado;
}
}
código AndroidManifast.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="alura.com.br">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Agenda">
<activity
android:name=".ui.activity.ListaAlunosActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activity.FormularioAlunoActivity"
android:exported="true"/>
</application>
</manifest>