Hide Date from Date Picker

前端 未结 6 1562
谎友^
谎友^ 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:59

    This worked for me after trying out several different approaches.

     datePicker = (DatePicker) findViewById(R.id.date_picker);
    
     public void hideDay() {
        try {
            java.lang.reflect.Field[] f = datePicker.getClass().getDeclaredFields();
            for (java.lang.reflect.Field field : f) {
                if (field.getName().equals("mDayPicker") || field.getName().equals("mDaySpinner")) {
                    field.setAccessible(true);
                    Object dmPicker = new Object();
                    dmPicker = field.get(datePicker);
                    ((View) dmPicker).setVisibility(View.GONE);
                }
            }
        }
        catch (SecurityException e) {
            TLog.d("ERROR", e.getMessage());
        }
        catch (IllegalArgumentException e) {
            TLog.d("ERROR", e.getMessage());
        }
        catch (IllegalAccessException e) {
            TLog.d("ERROR", e.getMessage());
        }
    }
    

提交回复
热议问题