Code example for DatePicker

Methods: getDayOfMonthgetMonthgetYearupdateDate

0
		//input validation 
		private boolean validation() 
		{ 
			String tempName = foodNameTextView.getText().toString().trim();
			Calendar tempDate = Calendar.getInstance();
			tempDate.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), 0, 0, 0);
			 
			//food name cannot be blank 
			if ("".equals(tempName))
			{ 
				showMsg("Please specify the name of food"); 
				return false; 
			} 
			//date should be later than current date 
			else if(!tempDate.after(currentDate))
			{ 
				showMsg("Maybe you should just throw it away..."); 
				return false; 
			} 
			else 
			{ 
				return true; 
			} 
		} 
 
		private void addOrEdit() 
		{ 
			XmlUtil xmlUtil = new XmlUtil();
			// determine if it is an "edit" action. 
			if (null != foodName) 
			{ 
				FoodInfo foodInfo = new FoodInfo(foodName, foodDate);
				// cancel old alarm 
				FoodReceiver alarm = new FoodReceiver(EditEntry.this, foodDate, false);
				// delete the old data entry 
				xmlUtil.deleteEntry(foodInfo);
			} 
			// get new input values  
			foodName = foodNameTextView.getText().toString().trim(); 
			if (null == foodDate) 
			{ 
				foodDate = Calendar.getInstance();
			} 
 
			foodDate.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), 0, 0, 0); 
			// update xml file 
			FoodInfo foodInfo = new FoodInfo(foodName, foodDate);
			xmlUtil.updateEntry(foodInfo);
			// set new alarm 
			FoodReceiver alarm = new FoodReceiver(EditEntry.this, foodDate, true);
			// popup toast confirming the submit 
			showMsg("Reminder added."); 
			// clear foodName & foodDate to avoid problems if user want to sumbit several items in a row 
			foodName = null; 
			foodDate = null; 
			// clear widgets 
			foodNameTextView.setText(""); 
			datePicker.updateDate(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DAY_OF_MONTH));
		} 
		 
		private void showMsg(String msg)
		{ 
			Toast.makeText(EditEntry.this, msg, Toast.LENGTH_SHORT).show();