1. In the VIEW area of your sketchware 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.
4. Add a new event button1 onClick. In the event insert an add source directly block and put following code:
showDatePickerDialog(button1);
5. Save and run the project. Now on clicking the Button, DatePickerDialog will appear.
0 Comments
Please comment on our page thank you