android


Hiding date and month from DatepickerDialog android


How can i hide the particular date and month field as well as date and year field and date and month and year field from the datepicker dialog android?
Im afraid theres no easy way to do this. You need to create your own custom class.
Take a look at accepted answer here :
Hide Date from Date Picker
try like this,
create Custom class for date Picker is Following that will update the date in title every time user change month/year
class CustomDatePickerDialog extends DatePickerDialog implements OnDateChangedListener {
private DatePickerDialog mDatePicker;
#SuppressLint("NewApi")
public CustomDatePickerDialog(Context context,int theme, OnDateSetListener callBack,
int year, int monthOfYear, int dayOfMonth) {
super(context, theme,callBack, year, monthOfYear, dayOfMonth);
mDatePicker = new DatePickerDialog(context,theme,callBack, year, monthOfYear, dayOfMonth);
mDatePicker.getDatePicker().init(2013, 7, 16, this);
updateTitle(year, monthOfYear);
}
public void onDateChanged(DatePicker view, int year,
int month, int day) {
updateTitle(year, month);
}
private void updateTitle(int year, int month) {
Calendar mCalendar = Calendar.getInstance();
mCalendar.set(Calendar.YEAR, year);
mCalendar.set(Calendar.MONTH, month);
// mCalendar.set(Calendar.DAY_OF_MONTH, day);
mDatePicker.setTitle(getFormat().format(mCalendar.getTime()));
}
public DatePickerDialog getPicker(){
return this.mDatePicker;
}
/*
* the format for dialog tile,and you can override this method
*/
public SimpleDateFormat getFormat(){
return new SimpleDateFormat("MMM, yyyy");
};
}
and use the following is the code that will hide the day and its spinner from the date picker dialog
CustomDatePickerDialog dp = new CustomDatePickerDialog(context, android.R.style.Theme_Holo_Light_Dialog, datePickerListener, year, month, day);
DatePickerDialog obj = dp.getPicker();
try{
Field[] datePickerDialogFields = obj.getClass().getDeclaredFields();
for (Field datePickerDialogField : datePickerDialogFields) {
if (datePickerDialogField.getName().equals("mDatePicker")) {
datePickerDialogField.setAccessible(true);
DatePicker datePicker = (DatePicker) datePickerDialogField.get(obj);
Field datePickerFields[] = datePickerDialogField.getType().getDeclaredFields();
for (Field datePickerField : datePickerFields) {
if ("mDayPicker".equals(datePickerField.getName()) || "mDaySpinner".equals(datePickerField
.getName())) {
datePickerField.setAccessible(true);
Object dayPicker = new Object();
dayPicker = datePickerField.get(datePicker);
((View) dayPicker).setVisibility(View.GONE);
}
}
}
}
}catch(Exception ex){
}
obj.show();

Related Links

Unable to get Lat Long from LocationManager
HttpURLConnection sending POST to a Web Service with FileNotFoundException
How to add an external storage to Microsoft android emulator?
How to show Password till the button is pressed
How do I access my current location in onLocationChanged, in onMapReady method?
Duplicate files copied in APK META-INF on many libraries?
admob banner ads overlaps main layout
How to build Tesseract OCR library for Android Studio?
Android Open and Close Database
set a layer-list item from SVG
How to Get location of a button and make Textview appear in the Center of button with Onclick
How to parse vector XML from SdCard on Android
Google Sign-In always returns false using gms:play-services-auth:8.3.0
How to using FCMPlugin in angularjs
UserNotAuthenticatedException during FingerprintManager.authenticate()
how to retrieve data from ms-sql database in a fragment?

Categories

HOME
service-worker
httparty
grok
google-cloud-platform
css3
android-studio-2.2
yandex
google-apps
code-coverage
emoji
mongodb-csharp
standards
wolframalpha
bourbon
guzzle
href
jquery-callback
expressionengine3
maze
corpus
appirater
mat
8051
tpm
user-defined-functions
dst
paragraph
fossil
nohup
gdata
hackintosh
file-sharing
signal-strength
fwrite
dynamic-linq
lampp
user-defined-fields
custom-font
context-sensitive-grammar
libjpeg
jtree
change-tracking
smartfoxserver
async.js
rspec2
x-tag
hclust
expectations
project-organization
toast
flock
zen-cart
rubaxa-sortable
rpart
dronekit-android
botan
kubuntu
document-repository
cocos3d
jama
mobility
lnk
grails-plugin-rabbitmq
buffering
cfcache
windows-embedded-standard
cocoalibspotify-2.0
mvc-editor-templates
alice
android-sdk-2.3
onmousemove
veracity
objectquery
josql
usertype
stress
virtualpathprovider
urlrewriter
box2d-iphone
expression-blend-4
screen-size
google-floodlight
photolibrary
silent
facebook-iframe
burndowncharts
tui
mathematical-notation
interop-domino
todos
sqlobject
lemmatization
wspbuilder

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App