Eu clico no aluno, ele abre o formulario com os dados referente aquele aluno, no entanto na hora de salvar, ele nunca entrar no método alterar
Formulario:
package br.com.anima.minhaagenda;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
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.Toast;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import br.com.anima.minhaagenda.dao.AlunoDAO;
import br.com.anima.minhaagenda.modelo.Aluno;
public class Formulario extends AppCompatActivity {
private FormularioHelper helper;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulario);
helper = new FormularioHelper(this);
Intent intent = getIntent();
Aluno aluno = new Aluno();
aluno = (Aluno) intent.getSerializableExtra("aluno");
if (aluno!=null){
helper.preencherFormulario(aluno);
}
}
@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.getAluno();
AlunoDAO dao = new AlunoDAO(this);
if (aluno.getId() != null) {
dao.atualiza(aluno);
} else {
dao.insere(aluno);
}
dao.close();
Toast.makeText(Formulario.this, "Aluno " + aluno.getNome() + " salvo!", Toast.LENGTH_SHORT).show();
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
FOrmularioHelper
package br.com.anima.minhaagenda;
import android.util.Log;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.Toast;
import br.com.anima.minhaagenda.modelo.Aluno;
/**
* Created by tharles on 19/09/16.
*/
public class FormularioHelper {
private final EditText nome;
private final EditText endereco;
private final EditText site;
private final RatingBar nota;
private Aluno aluno;
public FormularioHelper(Formulario formulario){
nome = (EditText) formulario.findViewById(R.id.formulario_nome);
endereco = (EditText) formulario.findViewById(R.id.formulario_endereco);
site = (EditText) formulario.findViewById(R.id.formulario_site);
nota = (RatingBar) formulario.findViewById(R.id.formulario_rating);
this.aluno=new Aluno();
}
public Aluno getAluno(){
Aluno aluno = new Aluno();
aluno.setNome(nome.getText().toString());
aluno.setEndereco(this.endereco.getText().toString());
aluno.setSite(this.site.getText().toString());
aluno.setNota(Double.valueOf(this.nota.getProgress()));
return aluno;
}
public void preencherFormulario(Aluno aluno) {
nome.setText(aluno.getNome());
endereco.setText(aluno.getEndereco());
site.setText(aluno.getSite());
nota.setProgress(aluno.getNota().intValue());
this.aluno=aluno;
}
}