This is the menu code:
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
try
{
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
if (!blnShort)
{
Posicao = info.position;
}
blnShort = false;
menu.setHeaderTitle("Selecione:");
String[] menuItems = getResources().getStringArray(R.array.menu);
for (int i = 0; i<menuItems.length; i++) {
menu.add(Menu.NONE, i, i, menuItems[i]);
}
}catch (Exception e) {
trace("Erro : " + e.getMessage());
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ListDesp meuItem = null;
try
{
int menuItemIndex = item.getItemId();
meuItem = (ListDesp) getListAdapter().getItem(Posicao);
if (menuItemIndex == 0){
Intent it = new Intent(this, CadDesp.class);
it.putExtra("tipo", ALTERAR);
it.putExtra("dadosLista", meuItem);
startActivityForResult(it, ALTERAR);
}else if (menuItemIndex == 1){
buscaDespesas.Excluir(meuItem);
listas.remove(meuItem);
adapter.notifyDataSetChanged();
}
}catch (Exception e) {
trace("Erro : " + e.getMessage());
}
return true;
}
And this is the exclude from the bank:
public void Excluir(ListDesp pValue) {
long id = pValue.getId();
database.delete(CriaDespesas.TABELA, CriaDespesas.DESP_ID + " = " + id, null);
}