Skip to content

Instantly share code, notes, and snippets.

@gturedi
Last active August 29, 2015 14:03
Show Gist options
  • Save gturedi/0229d3faf9c542506bb9 to your computer and use it in GitHub Desktop.
Save gturedi/0229d3faf9c542506bb9 to your computer and use it in GitHub Desktop.
"Android DatePickerDialog'daki DayPicker'i Gizleme" adlı blog postu icin kod ornegi: http://gturedi.blogspot.com.tr/2014/07/android-datepickerdialogdaki-daypickeri.html
package com.example.hide_day_picker;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import java.lang.reflect.Field;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void openDatePickerDialog(View view) throws IllegalAccessException {
final DatePickerDialog dialog = new DatePickerDialog(this, null, 2014, 1, 1);
// DatePicker sınıfının üye degiskenlerini al
Field[] fields = DatePicker.class.getDeclaredFields();
for (Field field : fields) {
// ilgilendiğimiz üye değişken mi?
if (field.getName().equalsIgnoreCase("mDaySpinner")) {
field.setAccessible(true);
Object dayPicker = field.get(dialog.getDatePicker());
((View) dayPicker).setVisibility(View.GONE);
}
}
// dialog.title'da gün bilgisi gösterimini engelleme
// DatePicker tipinin OnDateChangedListener eventini ancak initialization sırasında set edebiliyoruz
dialog.setTitle("choose date");
dialog.getDatePicker().init(2014, 1, 1, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker datePicker, int i, int i2, int i3) {
dialog.setTitle("choose date");
}
});
dialog.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment