Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid DatePicker month as integer
    primarykey
    data
    text
    <p>I have a simple question but after searching a while I couldn't find the answer yet. In a DatePicker, is it possible to change the month to be displayed as an integer not a string?.eg: {1,2,3..} not {jan,feb,mar...}</p> <p><strong>EDIT:</strong></p> <p>Although @kaneda's solution seems to work, in android 3.0 at least the methods and attributes are not the same. The code I'm using is this:</p> <pre><code>public DatePickerCustom(Context context, AttributeSet attrs) { super(context, attrs); Field[] fields = DatePicker.class.getDeclaredFields(); try { for (Field field : fields) { field.setAccessible(true); if (TextUtils.equals(field.getName(), "mMonthSpinner")) { Method m = field.getType().getDeclaredMethod("setDisplayedValues", String[].class); m.setAccessible(true); String[] s = new String[] {"01","02","03","04","05","06","07","08","09","10","11","12"}; Object[] params = new Object[1]; params[0] = s; m.invoke(field.get(this), params); break; } } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } </code></pre> <p><strong>EDIT 2:</strong></p> <p>Best solution, is to create a Custom DatePicker (following @kaneda first advice), will always work without compatibility issues and not relaying on reflection.</p> <p>Used the <a href="http://www.devdaily.com/java/jwarehouse/android-examples/platforms/android-2/data/res/layout/date_picker.xml.shtml" rel="nofollow">date_picker.xml</a> from android and DatePicker.java posted by @kaneda. Also, I used a custom NumberPicker (because the one the DatePicker widget uses is internal to android). For the NumberPicker widget I followed this <a href="http://www.quietlycoding.com/?p=5" rel="nofollow">link</a>.</p> <p>In the CustomDatePicker I commented the function <code>getShortMonths()</code> and set the month range as <code>mMonthPicker.setRange(1, NUMBER_OF_MONTHS);</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload