@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo info; try { // Casts the incoming data object into the type for AdapterView objects. info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { // If the menu object can't be cast, logs an error. Log.e(TAG, "bad menuInfo", e); return; } StrngData strngdata = strngdata_adapter.getItem(info.position); menu.setHeaderTitle("Action: " + strngdata.toString()); getActivity().getMenuInflater().inflate(R.menu.string_list_item_context, menu); }
private void alertMessageDeleteString(final StrngData strngdata) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); // Setting Dialog Title alertDialog.setTitle("Confirm Delete..."); // Setting Dialog Message alertDialog.setMessage("Delete " + strngdata.toString() + "?"); // Setting Icon to Dialog // alertDialog.setIcon(R.drawable.delete); // Setting Positive "Yes" Button alertDialog.setPositiveButton( "YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Yes button clicked UUID racketId = (UUID) getActivity() .getIntent() .getSerializableExtra( RacketFragment.EXTRA_RACKET_ID); // chapter 10: direct method: RacketList.get(getActivity()).getRacket(racketId).deleteStrngData(strngdata); RacketList.get(getActivity()) .saveRackets(); // kluge: could not be done in deleteStrngData strngdata_adapter.notifyDataSetChanged(); } }); // Setting Negative "NO" Button alertDialog.setNegativeButton( "NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // No button clicked // do nothing dialog.cancel(); } }); // Showing Alert Message alertDialog.show(); }