@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (v.getId() == R.id.lpListViewProducts) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; Product p = (Product) productsListView.getAdapter().getItem(info.position); menu.setHeaderTitle(p.getName()); menu.add(0, R.string.lpContextMenuShowProduct, 0, R.string.lpContextMenuShowProduct); menu.add(0, R.string.lpContextMenuEditProduct, 1, R.string.lpContextMenuEditProduct); menu.add(0, R.string.lpContextMenuDeleteFromDB, 2, R.string.lpContextMenuDeleteFromDB); } super.onCreateContextMenu(menu, v, menuInfo); }
private void updateView() { Type selectedType = (Type) (typeSpinner.getSelectedItem()); if (selectedType != null) { int typeID = selectedType.getId(); // Load productList by selectedTypeID productList = Product.getProductsByType(typeID, getApplicationContext()); } else { productList = Product.getAllProducts(getApplicationContext()); } ArrayAdapter<Product> arrayAdapter = new ArrayAdapter<Product>( getApplicationContext(), android.R.layout.simple_list_item_1, productList); productsListView.setAdapter(arrayAdapter); }
private void editProduct(Product selectedProduct) { Intent intentEditProduct = new Intent(getApplicationContext(), EditProduct.class); Bundle b = new Bundle(); b.putString("CurrentProductBarcode", selectedProduct.getBarCode()); intentEditProduct.putExtras(b); startActivityForResult(intentEditProduct, INTENT_RESULT_EDIT); }
private void showProduct(Product p) { Intent intentShowProduct = new Intent(getApplicationContext(), ShowProduct.class); Bundle b = new Bundle(); b.putString("CurrentProductBarcode", p.getBarCode()); intentShowProduct.putExtras(b); startActivityForResult(intentShowProduct, INTENT_RESULT_SHOW); }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Product selectedProduct = (Product) productsListView.getAdapter().getItem(info.position); switch (item.getItemId()) { case R.string.lpContextMenuShowProduct: showProduct(selectedProduct); break; case R.string.lpContextMenuEditProduct: editProduct(selectedProduct); break; case R.string.lpContextMenuDeleteFromDB: selectedProduct.delete(true); break; } updateView(); return true; }