Code example for AlertDialog.Builder

Methods: setMessage, setNegativeButton, setPositiveButton, setTitle, show

0
			deleteContext = this;
			verifyDelete(); 
		} 
	} 
	private void verifyDelete() { 
		Builder alert = new AlertDialog.Builder(this);
		alert.setTitle("Caution");
		alert.setMessage("Are you sure you want to delete this play from the gameplan?");
		alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				gameplanPlays.remove(positionSelected);
				 
				//store to database 
				int index = gameplansSpinner.getSelectedItemPosition();
				GamePlan gameplan = new GamePlan();
				if(index >= 0){
					gameplan.setGamePlanName(gameplansSpinner.getAdapter().getItem(index).toString());
					gameplan.addPlaysToGameplan(gameplanPlays);
					DigPlayDB.getInstance(getBaseContext()).storeGamePlan(gameplan);
				} 
					 
				ArrayAdapter<String> thisAdapter = new ArrayAdapter<String>(deleteContext,android.R.layout.simple_list_item_1,gameplanPlays);
				gameplanLV.setAdapter(thisAdapter);
			} 
		}); 
		alert.setNegativeButton("Cancel", null);
		alert.show();
	} 
	public void onClick(View v) {		
		if(v.getId() == delete.getId()){
			if(!deletePressed){
				delete.setBackgroundColor(Color.YELLOW);
Stop searching for code, let great code find you!  Add Codota to your java IDE