package com.example.agenda;
import android.app.Activity;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.agenda.DAO.AlunoDao;
import com.example.agenda.modelo.Aluno;
public class Formulario extends AppCompatActivity {
private formularioHelper helper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulario);
helper = new formularioHelper(this);
Intent intent = getIntent();
Aluno aluno = (Aluno) intent.getSerializableExtra("aluno");
if (aluno != null) {
helper.preencheFormulario(aluno);
}
/* Button botaoSalvar = (Button) findViewById(R.id.formulario_salvar);
botaoSalvar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Formulario.this, "Cadastro Salvo!", Toast.LENGTH_SHORT).show();
Intent VaiPraLista = new Intent(Formulario.this, MainActivity.class);
finish();
}
});*/
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_formulario, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_formulario_ok:
Aluno aluno = helper.pegaAluno();
AlunoDao dao = new AlunoDao(this);
if (aluno.getId() != null){
dao.alteraAluno(aluno);
} else {
dao.insere(aluno);
}
dao.close();
Toast.makeText(Formulario.this, aluno.getNome()+" Salvo!", Toast.LENGTH_SHORT).show();
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
Já conferi o aluno.getId() =! null, não sei se a linha do código do preencher lá encima pode estar dando erro.