public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int menuItemIndex = item.getItemId(); Interes interes = interesesAdapter.getItem(info.position); switch (menuItemIndex) { case R.id.ItemMenuBorrar: OrmLiteSqliteOpenHelper helper = null; try { helper = OpenHelperManager.getHelper(this, DatabaseHelper.class); Dao<Interes, Integer> interesesDao = helper.getDao(Interes.class); interesesDao.delete(interes); interesesAdapter.remove(interes); } catch (Exception e) { Log.e(TAG, "Error al listar los intereses", e); GuiUtils.mostrarToast(this, R.string.operacion_error, null); } finally { try { OpenHelperManager.releaseHelper(); } catch (Exception e2) { } } return true; case R.id.ItemMenuEditar: mostrarDatosInteres(interes); return true; default: return super.onContextItemSelected(item); } }
private void cargarListadoIntereses() { OrmLiteSqliteOpenHelper helper = null; try { helper = OpenHelperManager.getHelper(this, DatabaseHelper.class); Dao<Interes, Integer> interesDao = helper.getDao(Interes.class); List<Interes> intereses = interesDao.queryForAll(); interesesAdapter = new ArrayAdapter<Interes>(this, android.R.layout.simple_list_item_1, intereses); listViewIntereses.setAdapter(interesesAdapter); } catch (Exception e) { Log.e(TAG, "Error al cargar los clientes", e); GuiUtils.mostrarToast(this, R.string.operacion_error, null); } finally { try { OpenHelperManager.releaseHelper(); } catch (Exception e2) { Log.e(TAG, "Error en el release", e2); } } }