Code example for Spinner

Methods: getAdapter, getItemAtPosition, setSelection

0
    } 
 
	@SuppressWarnings("unchecked") 
	private void setEndSpinner(Date date)
	{ 
		ArrayAdapter<String> adapter = (ArrayAdapter<String>)mEndSpinner.getAdapter();
		if (adapter.getCount() > 2)
			return; 
		 
		Calendar cal = Calendar.getInstance();
		if (date != null)
			cal.setTime(date);
		DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
		 
		String str = df.format(cal.getTime());
		mOldDate = str;
		adapter.add(str);
	} 
	 
	private Date parseEndSpinner()
	{ 
		Date date;
		DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
		 
		try 
		{ 
			date = df.parse(mOldDate);
    		Calendar cal = Calendar.getInstance();
    		cal.setTime(date);
    		cal.set(Calendar.HOUR, 0);
    		cal.set(Calendar.MINUTE, 0);
    		cal.set(Calendar.SECOND, 0);
    		date = cal.getTime();
		} 
		catch (Exception e)
		{ 
			// set the date to null if there's a parsing error 
			// the choice was set to 'No End Date' 
			date = null;
		} 
		 
		return date;
	} 
	 
	private int[] endSpinnerToYMD() 
	{ 
		int[] ymd = new int[3];
		Date date = parseEndSpinner();
		Calendar cal = Calendar.getInstance();
		if (date != null)
			cal.setTime(date);
		ymd[0] = cal.get(Calendar.YEAR);
		ymd[1] = cal.get(Calendar.MONTH);
		ymd[2] = cal.get(Calendar.DAY_OF_MONTH);
		 
		return ymd;
	} 
	 
	private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() 
		{ 
            public void onDateSet(DatePicker view, int year, int month,  int day) 
            { 
            	Calendar cal = Calendar.getInstance(); 
            	cal.set(Calendar.YEAR, year); 
            	cal.set(Calendar.MONTH, month); 
            	cal.set(Calendar.DAY_OF_MONTH, day); 
            	setEndSpinner(cal.getTime()); 
            	mOldDate = (String)mEndSpinner.getItemAtPosition(2); 
            	mEndSpinner.setSelection(2); 
            } 
        }; 
         
    @Override 
	protected Dialog onCreateDialog(int id)