FileDocCategorySizeDatePackage
DateWidgets1.javaAPI DocGoogle Android v1.5 Example3924Sun Nov 11 13:01:04 GMT 2007com.google.android.samples.view

DateWidgets1

public class DateWidgets1 extends android.app.Activity
Basic example of using date and time widgets, including {@link android.app.TimePickerDialog} and {@link android.widget.DatePicker}.

Fields Summary
private android.widget.TextView
mDateDisplay
private int
mYear
private int
mMonth
private int
mDay
private int
mHour
private int
mMinute
private DatePicker.OnDateSetListener
mDateSetListener
private TimePicker.OnTimeSetListener
mTimeSetListener
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        setContentView(R.layout.date_widgets_example_1);

        mDateDisplay = (TextView) findViewById(R.id.dateDisplay);

        Button pickDate = (Button) findViewById(R.id.pickDate);
        pickDate.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                new DatePickerDialog(DateWidgets1.this,
                        mDateSetListener,
                        mYear, mMonth, mDay, Calendar.SUNDAY).show();
            }
        });

        Button pickTime = (Button) findViewById(R.id.pickTime);
        pickTime.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                new TimePickerDialog(DateWidgets1.this,
                        mTimeSetListener, "Set the time",
                        mHour, mMinute, false).show();
            }
        });

        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
        mHour = c.get(Calendar.HOUR_OF_DAY);
        mMinute = c.get(Calendar.MINUTE);

        updateDisplay();
    
private static java.lang.Stringpad(int c)


         
        if (c >= 10)
            return String.valueOf(c);
        else
            return "0" + String.valueOf(c);
    
private voidupdateDisplay()

        mDateDisplay.setText(
            new StringBuilder()
                    .append(mMonth).append("-")
                    .append(mDay).append("-")
                    .append(mYear).append(" ")
                    .append(pad(mHour)).append(":")
                    .append(pad(mMinute)));