DatePickerDialog in Sketchware
To create a DatePickerDialog in Sketchware android project follow the steps given below.
1. In VIEW area of your sketchware android project, insert a LinearH and inside it insert a TextView textview1, an EditText edittext1 and an ImageView imageview1.
For textview1 write text as 'Date:'. For edittext1 write hint as dd/mm/yyyy and deselect 'enabled' in it's properties.
2. Choose image of a Calendar using image manager and set it as image of imageview1.
3. Switch On AppCompat and Design.
4. Create a More Block showDatePicker. In this block, use an add source directly block and put following code.
androidx.appcompat.app.AppCompatDialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "Date Picker");
5. Create another More Block extra. In this put codes to define a DialogFragment.
}
public static class DatePickerFragment extends androidx.appcompat.app.AppCompatDialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
int mon = month +1;
String date = day + "/" + mon + "/" + year;
EditText edittext1 = (EditText) getActivity().findViewById(R.id.edittext1);
edittext1.setText(date);
}
Gestational Age Calculator using DatePickerDialog in Sketchware:
Post a Comment