INFORMATION
It doesn’t work on Nougat, Android 7.0+
To create a dialog with spinner theme on SKETCHWARE please follow the below steps.
1. In VIEW area of your sketchware android project, insert a LinearH and inside it insert a TextView textview1, and a Button button1.
2. Add a More Block ‘extra‘.
3. To define the block extra, insert an add source directly block and put following code in it:
}
public void showDatePickerDialog(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
public class DatePickerFragment extends DialogFragment 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(), android.R.style.Theme_Holo_Dialog, this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
int mon = month +1;
String date = day + "/" + mon + "/" + year;
textview1.setText(date);
}
For light theme replace
android.R.style.Theme_Holo_Dialog
With
android.R.style.Theme_Holo_Light_Dialog
in the code above.
Replaced code is below
}
public void showDatePickerDialog(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
public class DatePickerFragment extends DialogFragment 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(), android.R.style.Theme_Holo_Light_Dialog, this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
int mon = month +1;
String date = day + "/" + mon + "/" + year;
textview1.setText(date);
}
4. Add a new event button1 onClick. In the event insert an add source directly block and put following code:
showDatePickerDialog(button1);
Now save and run the project. Now on clicking the Button, DatePickerDialog will appear.
Test result In various persons
90% success and success even while edited to only month select. The test may be not currect we will test between our team between 2021 January last