Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ScanActivity extends Activity {
- EditText date;
- DatePickerDialog datePickerDialog;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_scan);
- date = (EditText) findViewById(R.id.date);
- date.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // calender class's instance and get current date , month and year from calender
- final Calendar c = Calendar.getInstance();
- int mYear = c.get(Calendar.YEAR); // current year
- int mMonth = c.get(Calendar.MONTH); // current month
- int mDay = c.get(Calendar.DAY_OF_MONTH); // current day
- // date picker dialog
- datePickerDialog = new DatePickerDialog(ScanActivity.this,
- new DatePickerDialog.OnDateSetListener() {
- @Override
- public void onDateSet(DatePicker view, int year,
- int monthOfYear, int dayOfMonth) {
- // set day of month , month and year value in the edit text
- date.setText(year + "-"
- + (monthOfYear + 1) + "-" + dayOfMonth);
- }
- }, mYear, mMonth, mDay);
- datePickerDialog.show();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement