-
-
Save jezinka/2ad18f8be0920c7b78bd525a612b24c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.menu_with_delete_icon, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
case R.id.delete_menu_button: | |
ArrayList<Long> ingredientIds = new ArrayList<Long>(); | |
for (int i = 0; i < adapter.getCount(); i++) { | |
Ingredient ingredient = adapter.getItem(i); | |
if (ingredient != null && ingredient.isChecked()) { | |
ingredientIds.add(ingredient.getId()); | |
} | |
} | |
toggleCheckboxesAndToolbar(); | |
ingredientContract.delete(ingredientIds.toArray(new Long[ingredientIds.size()]), helper); | |
adapter.updateResults(ingredientContract.getAllIngredientsArray(helper)); | |
return true; | |
default: | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment