Example usage for android.app DatePickerDialog show

List of usage examples for android.app DatePickerDialog show

Introduction

In this page you can find the example usage for android.app DatePickerDialog show.

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:dev.memento.MainActivity.java

public void showDatePicker(View v) {

    // Date picker's months range from 0-11
    final DatePickerDialog dateDialog = new DatePickerDialog(this, null, mDateChosen.getYear(),
            mDateChosen.getMonth() - 1, mDateChosen.getDay());

    // Have to set positive and negative buttons because only a positive button
    // will be displayed by default, and there is a bug in Android that causes
    // the Back button (which should normally be used to cancel) to cause
    // the onDateTime event handler to be triggered.  
    // http://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel

    // If either of the buttons are set with .setButton(), the OnDateSetListener is 
    // not triggered on my Galaxy Tab (Android 4.0.4), so implement listening here instead.

    dateDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.button_set),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    DatePicker dp = dateDialog.getDatePicker();
                    dateSelected(dp.getDayOfMonth(), dp.getMonth(), dp.getYear());
                }/*from  w  ww. j a v a2 s.c o m*/
            });

    dateDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.button_cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // Nothing to do
                    if (Log.LOG)
                        Log.d(LOG_TAG, "Cancel was pressed");
                }
            });

    dateDialog.show();
}

From source file:com.alivenet.dmv.driverapplication.fragment.MyAccount.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.myaccount, container, false);
    getActivity().setTitle("      MY ACCOUNT");
    spincabname = (Spinner) view.findViewById(R.id.cabspinner);
    profile_image = (ImageView) view.findViewById(R.id.img_prifile_show);
    fname = (EditText) view.findViewById(R.id.edit_firname);
    lname = (EditText) view.findViewById(R.id.edit_lname);
    pass = (EditText) view.findViewById(R.id.edit_pass);
    dctc = (EditText) view.findViewById(R.id.edit_dctc);
    experdate = (TextView) view.findViewById(R.id.edit_exprdate);
    cell = (TextView) view.findViewById(R.id.edit_cell);
    email = (TextView) view.findViewById(R.id.edit_email);
    licenid = (EditText) view.findViewById(R.id.edit_licenid);
    proofincu = (EditText) view.findViewById(R.id.edit_proofinsu);
    nameinsu = (EditText) view.findViewById(R.id.edit_nameinsu);
    vehicle = (EditText) view.findViewById(R.id.edit_vehicle);
    tabsate = (EditText) view.findViewById(R.id.edit_tabstate);
    et_pvin = (EditText) view.findViewById(R.id.edit_pvin);
    btndriver = (Button) view.findViewById(R.id.btndriver);

    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);

    mTypeface = Typeface.createFromAsset(getActivity().getAssets(), "System San Francisco Display Regular.ttf");
    getFontFamily();//from www.  j  av a2 s.c o  m

    if (CommonMethod.isOnline(getActivity())) {

        Myaccountdata myacc = new Myaccountdata();
        myacc.execute();

        GetCablistAsync cablist = new GetCablistAsync();
        cablist.execute();

    } else {
        CommonMethodUtil.showAlert("Please connect internet", getActivity());
    }

    profile_image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            showActionSheet();

        }
    });

    experdate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Calendar c = Calendar.getInstance();
            mYear = c.get(Calendar.YEAR);
            mMonth = c.get(Calendar.MONTH);
            mDay = c.get(Calendar.DAY_OF_MONTH);
            // Launch Date Picker Dialog
            DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            // Display Selected date in textbox
                            MyApplication.dataupdateflag = true;
                            try {
                                expiration_date = String.format("%02d", dayOfMonth) + "-"
                                        + String.format("%02d", (monthOfYear + 1)) + "-" + year;

                                SharedPreferences.Editor editor = mPref.edit();
                                editor.putString("dateformat1", expiration_date);
                                editor.apply();
                                Log.e("monthe", "" + monthOfYear);
                                if (monthOfYear == 0) {
                                    monthd = "Jan";
                                } else if (monthOfYear == 1) {
                                    monthd = "Feb";
                                } else if (monthOfYear == 2) {
                                    monthd = "Mar";
                                } else if (monthOfYear == 3) {
                                    monthd = "Apr";
                                } else if (monthOfYear == 4) {
                                    monthd = "May";
                                } else if (monthOfYear == 5) {
                                    monthd = "Jun";
                                } else if (monthOfYear == 6) {
                                    monthd = "Jul";
                                } else if (monthOfYear == 7) {
                                    monthd = "Aug";
                                } else if (monthOfYear == 8) {
                                    monthd = "Sept";
                                } else if (monthOfYear == 9) {
                                    monthd = "Oct";
                                } else if (monthOfYear == 10) {
                                    monthd = "Nov";
                                } else if (monthOfYear == 11) {
                                    monthd = "Dec";
                                }
                                getdate = monthd + "  " + String.valueOf(dayOfMonth) + ","
                                        + String.valueOf(year);
                                System.out.println("dateprntln>>>>>>>>>>" + getdate);

                                // Display Selected date in textbox
                                experdate.setText(getdate);

                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            //experdate.setText(String.format("%02d", dayOfMonth) + "-" + String.format("%02d", (monthOfYear + 1)) + "-" + year);
                        }
                    }, mYear, mMonth, mDay);
            dpd.getDatePicker();
            dpd.show();

        }
    });

    spincabname.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            if (position > 0) {
                if (cabtypeList != null) {
                    cabId = cabtypeList.get(position - 1).getCabId();
                }

            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    btndriver.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (CommonMethod.isOnline(getActivity())) {
                if (checkValidationUpdateProfile()) {
                    UPdateProfile update = new UPdateProfile();
                    update.execute();
                    /*  if(CommonMethod.getprofileupdate(getActivity()))
                      {
                    CommonMethodUtil.showAlert("You cant update profile after accepting ride .", getActivity());
                      }else {
                            
                      }*/
                }

            } else {
                CommonMethodUtil.showAlert("Please connect internet", getActivity());
            }

        }
    });

    return view;
}