Não esta selecionado o item de menu para deletar Segue o codigo da Lista de alunos
package br.com.embrapa.agendateste;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.List;
import br.com.embrapa.agendateste.dao.AlunoDAO;
import br.com.embrapa.agendateste.modelo.Aluno;
public class ListaAlunosActivity extends AppCompatActivity {
private ListView listaAlunos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_alunos);
listaAlunos = (ListView) findViewById(R.id.Lista_alunos);
Button novo_aluno = (Button) findViewById(R.id.novo_aluno);
novo_aluno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentVaiProFormulario = new Intent(ListaAlunosActivity.this, FormularioActivity.class);
startActivity(intentVaiProFormulario);
}
});
}
private void carregaLista() {
AlunoDAO dao = new AlunoDAO(this);
List<Aluno> alunos = dao.buscaAlunos();
dao.close();
ArrayAdapter<Aluno> adapter = new ArrayAdapter<Aluno>(this, android.R.layout.simple_list_item_1, alunos);
listaAlunos.setAdapter(adapter);
}
@Override
protected void onResume() {
super.onResume();
carregaLista();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, final ContextMenu.ContextMenuInfo menuInfo) {
MenuItem deletar = menu.add("Deletar");
deletar.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(info.position);
AlunoDAO dao = new AlunoDAO(ListaAlunosActivity.this);
dao.deleta(aluno);
dao.close();
carregaLista();
return false;
}
});
}
}