Thursday, November 5, 2009

DatePicker Widget

I've finally started working on my first app. I needed to use a DatePicker but didn't want to use a dialog, I wanted the DatePicker to appear on the current page. Here is my code:


/**
* DatePickerActivity
*
*
*/
public class DatePickerActivity extends Activity {

private DatePicker datePicker;

private int year;
private int month;
private int day;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

////////////////////////////////////////////////////////////
// Get access to Date Picker
datePicker = (DatePicker)findViewById(R.id.DatePicker01);

Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);

datePicker.init(year, month, day, dateSetListener);
}


/**
* DatePicker.OnDateChangedListener
*
*/
private DatePicker.OnDateChangedListener dateSetListener
= new DatePicker.OnDateChangedListener() {

/*
* onDateChanged
*/
public void onDateChanged(DatePicker view, int newYear,
int newMonth, int newDay) {

String dateOutput = String.format("Date Selected: %02d/%02d/%04d",
newDay, newMonth, newYear);
Log.i("Debug", dateOutput);
}
};
}

1 comment:

  1. With the aid of|assistance from|the help of} our ingenious Green Gaming device, players can look at their betting conduct and determine if 코인카지노 it is sound or unsafe. The device comprises of an easy self-evaluation check that we mix with individual info on actual game-play to compute a playing conduct profile. This info is then used to make a custom-made suggestion for a wholesome enjoying in} conduct. They are usually divided into two distinct sorts; Free Spins or a free amount of money.

    ReplyDelete