Delete Item menu context action ORMLITE

0

Good evening. I have an app that when clicked a simple contextual action menu appears and one of the options is to delete. Below the method for contextual action

@Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        AdapterView.AdapterContextMenuInfo info;

        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

        Extintores extintores = (Extintores) listViewExtintores.getSelectedItemPosition();

        switch (item.getItemId()){
            case R.id.deleta_item:
                excluirExtintor(extintores);
                mode.finish();
                return true;
            case R.id.altera_item:
                //excluir();
                mode.finish();//Fecha o menu apos clicar no icone
                return true;
            case R.id.servicos_item:
                Intent intent_servicos = new Intent(getApplicationContext(), ServicosActivity.class);
                startActivity(intent_servicos);
                mode.finish();
                return true;
            default:
                return false;
        }
    }

Selecting to delete it redirects to the following method.

private void excluirExtintor(final Extintores extintores){
    String mensagem = getString(R.string.deseja_realmente_apagar)
            + "\n";

    DialogInterface.OnClickListener listener =
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    switch(which){
                        case DialogInterface.BUTTON_POSITIVE:

                            try {
                                DatabaseHelper conexao =
                                        DatabaseHelper.getInstance(PrincipalActivity.this);

                                conexao.getExtintoresDAO().delete(extintores);

                                listaAdapter.remove(extintores);

                            } catch (SQLException e) {
                                e.printStackTrace();
                            }

                            break;
                        case DialogInterface.BUTTON_NEGATIVE:

                            break;
                    }
                }
            };

    UtilsGUI.confirmaAcao(PrincipalActivity.this, mensagem, listener);
}

My difficulty is in calling the delete method how will I move the position of the selected item?

    
asked by anonymous 06.06.2018 / 02:13

0 answers