Como posicionar o item no centro da tela? Imagem de como está: https://pasteboard.co/HoqNztX.png
Métodos:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_context_deletar, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menu_lista_deletar:
ContextMenu.ContextMenuInfo menuInfo = item.getMenuInfo();
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(info.position);
AlunoDAO dao = new AlunoDAO(this);
dao.deleta(aluno);
dao.close();
Toast.makeText(ListaAlunosActivity.this, "Aluno " + aluno.getNome() + " deletado!", Toast.LENGTH_SHORT).show();
carregaLista();
break;
}
return super.onContextItemSelected(item);
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="br.com.joaoraphael.agenda.ListaAlunosActivity">
<item
android:id="@+id/menu_lista_deletar"
android:title="Deletar" />
</menu>