Date and time picker in Sketchware

1. Create a new project in Sketchware.

2. Add a Button button1 for picking date and time.

3. Add a TextView textview1, for displaying the selected date and time.

4. Add a Calendar component cal.

5. Create two more blocks, pickDate and pickTime.

6. In pickDate more block, use an add source directly block and put following code:



DatePickerDialog datePicker = new DatePickerDialog(
    this,
    new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
_pickTime();
}
},
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH)
);
        datePicker.show();

7. In pickTime more block, use an add source directly block and put following code:



TimePickerDialog timePicker = new TimePickerDialog(
    this,
    new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, 0);

textview1.setText(new SimpleDateFormat("dd/MM/yyyy hh:mm a").format(cal.getTime()));
        }
    },
    cal.get(Calendar.HOUR_OF_DAY),
    cal.get(Calendar.MINUTE),
    true
);
timePicker.show();

8. In button1 onClick event, use the pickDate more block.

9. Save and run the project.


Comments

  1. I appreciate how MyTechStock consistently offers high-value content that blends technology updates with strategic investment viewpoints. It empowers readers with knowledge that feels both practical and forward-thinking, making it an exceptional resource in today’s fast-changing digital world.

    ReplyDelete
  2. NewerSlim redefines how we engage with global news, blending smart analysis with technology trends and cultural commentary. It’s refreshing to have a platform that values depth, insight, and a sophisticated approach to today’s most pressing stories.

    ReplyDelete
  3. I’m impressed by TechNewsIdeas’ dedication to quality and depth. The site doesn’t just report trends—it analyzes their implications, helping readers understand the potential impact of innovation on society, business, and everyday life.

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

How to enable upload from webview in Sketchware?

Simple Audio recorder app in Sketchware

Custom dialog box in Sketchware using CustomView

How to create a custom ListView in Sketchware?