Hide Date from Date Picker

前端 未结 6 1583
谎友^
谎友^ 2020-12-18 13:16

Currently I am using date picker native one but i want to change it in such a way that i only needed month and year how to modify this my code is following



        
6条回答
  •  死守一世寂寞
    2020-12-18 13:50

    I modified few things like: Made style the android default Theme_Holo_Dialog and delete the day from the visibility.

    Following few changes my code is:

    pick_expire_date.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Get Current Date
                final Calendar c = Calendar.getInstance();
                cyear = c.get(Calendar.YEAR);
                cmonth = c.get(Calendar.MONTH);
                cday = c.get(Calendar.DAY_OF_MONTH);
    
                DatePickerDialog datePickerDialog = new DatePickerDialog(
                        CheckoutPaymentActivity.this,
                        android.R.style.Theme_Holo_Dialog,
                        new DatePickerDialog.OnDateSetListener() {
                            @Override
                            public void onDateSet(DatePicker view, int year,
                                                  int monthOfYear, int dayOfMonth) {
                                pick_expire_date.setText((monthOfYear + 1)+"/"+year);
                                mMonth = monthOfYear + 1;
                                mYear = year;
                            }
                        },
                        cyear, cmonth, cday);
                datePickerDialog.getDatePicker().findViewById(getResources().getIdentifier("day","id","android")).setVisibility(View.GONE);
                datePickerDialog.show();
            }
        });
    

提交回复
热议问题