本文整理汇总了Java中android.widget.DatePicker.init方法的典型用法代码示例。如果您正苦于以下问题:Java DatePicker.init方法的具体用法?Java DatePicker.init怎么用?Java DatePicker.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.DatePicker
的用法示例。
在下文中一共展示了DatePicker.init方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDate
import android.widget.DatePicker; //导入方法依赖的package包/类
/**
* Set the initial date, default date is 1980-01-01
* @param picker
* @param date initial date, format is 'yyyyy-MM-dd'
*/
@ReactProp(name="date")
public void setDate(DatePicker picker ,String date) {
@SuppressLint("SimpleDateFormat") SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d = null;
try {
d = df.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
if (d == null) {
picker.init(1980, 0, 1, listener);
} else {
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
picker.init(calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
listener);
}
}
开发者ID:vincentsong,项目名称:react-native-datepicker-component-android,代码行数:26,代码来源:RNDatePickerComponentViewManager.java
示例2: DateDialog
import android.widget.DatePicker; //导入方法依赖的package包/类
/**
* 显示时间窗口
*
* @param textView
*/
public static void DateDialog(final Context mContext, final TextView textView) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View v = inflater.inflate(R.layout.date_picker, null);
final DatePicker dataPicker = (DatePicker) v.findViewById(R.id.datePicker);
Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
dataPicker.init(mYear, mMonth, mDay, (datePicker, year, month, day) -> {
mYear = year;
mMonth = month;
mDay = day;
});
new MaterialDialog.Builder(mContext)
.customView(v, false)
.positiveText(android.R.string.ok)
.negativeText(android.R.string.cancel)
.onPositive((dialog, which) -> {
textView.setText(mYear + "-" + (mMonth + 1) + "-" + mDay);
}).show();
}
示例3: pickMonth
import android.widget.DatePicker; //导入方法依赖的package包/类
/**
* 年月选择对话框
*
* @param con
* @param title
* @param calendar
* @param listener
*/
public static void pickMonth(Context con, String title, Calendar calendar, final OnDateSetListener listener) {
LinearLayout ll = new LinearLayout(con);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ll.setLayoutParams(layoutParams);
ll.setOrientation(LinearLayout.VERTICAL);
//添加一条线
LinearLayout line = new LinearLayout(con);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
line.setBackgroundColor(con.getResources().getColor(R.color.line));
line.setLayoutParams(lp);
ll.addView(line);
//添加选择器控件
final DatePicker datePicker = new DatePicker(con, null, themeId);
datePicker.setLayoutParams(layoutParams);
datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), null);
datePicker.setCalendarViewShown(false);
ll.addView(datePicker);
//初始化对话框
QuickDialog.Builder builder = new QuickDialog.Builder(con);
builder.setContentView(ll);
builder.setTitle(title);
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
listener.onDateSet(datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
}
});
builder.create().show();
}
示例4: onCreateContentView
import android.widget.DatePicker; //导入方法依赖的package包/类
@Override
protected View onCreateContentView(Bundle savedInstanceState) {
picker = new DatePicker(getContext());
Calendar c = Calendar.getInstance();
if (savedInstanceState != null){
c.setTimeInMillis(savedInstanceState.getLong(DATE));
} else if (getArguments().containsKey(DATE)) {
c.setTimeInMillis(getArguments().getLong(DATE));
}
picker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), this);
if (getArguments().containsKey(MIN_DATE)) {
picker.setMinDate(getArguments().getLong(MIN_DATE));
}
if (getArguments().containsKey(MAX_DATE)) {
picker.setMaxDate(getArguments().getLong(MAX_DATE));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& getArguments().containsKey(FIRST_DAY_OF_WEEK)) {
picker.setFirstDayOfWeek(getArguments().getInt(FIRST_DAY_OF_WEEK));
}
return picker;
}
示例5: showDialogDatePicker
import android.widget.DatePicker; //导入方法依赖的package包/类
public void showDialogDatePicker(){
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.DialogTransBackGround);
final AlertDialog dialog_date = builder.create();
dialog_date.show();
View view_dialog = LayoutInflater.from(context).inflate(R.layout.item_dialog_datepicker, null);
dialog_date.setContentView(view_dialog);
DatePicker picker = (DatePicker) view_dialog.findViewById(R.id.date_picker);
Button bt_yes = (Button) view_dialog.findViewById(R.id.bt_yes);
Button bt_no = (Button) view_dialog.findViewById(R.id.bt_no);
Calendar calendar = Calendar.getInstance();
int int_Year = calendar.get(Calendar.YEAR);
int int_Month = calendar.get(Calendar.MONTH);
int int_Day = calendar.get(Calendar.DAY_OF_MONTH);
time = int_Year + "-" + String.format("%02d", (int_Month + 1)) + "-" + String.format("%02d", int_Day);
picker.init(int_Year, int_Month, int_Day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker datePicker, int i, int i1, int i2) {
Log.e("aaa", "" + i2);
time = i + "-" + String.format("%02d", (i1 + 1)) + "-" + String.format("%02d", i2);
}
});
bt_yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
et_add_time.setText(time);
dialog_date.dismiss();
}
});
bt_no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog_date.dismiss();
}
});
}
示例6: DateDialog1
import android.widget.DatePicker; //导入方法依赖的package包/类
public static void DateDialog1(final Context mContext, final TextView textView) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View v = inflater.inflate(R.layout.date_picker, null);
final DatePicker dataPicker = (DatePicker) v.findViewById(R.id.datePicker);
Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
dataPicker.init(mYear, mMonth, mDay, (datePicker, year, month, day) -> {
mYear = year;
mMonth = month;
mDay = day;
});
new MaterialDialog.Builder(mContext)
.customView(v, false)
.positiveText(android.R.string.ok)
.negativeText(android.R.string.cancel)
.onPositive((dialog, which) -> {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
beginDate = sdf.parse(mYear + "-" + (mMonth + 1) + "-" + mDay);
//得到long类型当前时间
long l = System.currentTimeMillis();
//new日期对象
Date date = new Date(l);
if (beginDate.getTime() < date.getTime())
textView.setText(mYear + "-" + (mMonth + 1) + "-" + mDay);
else
Toast.makeText(mContext, "开始日期不能大于当前日期", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}).show();
}
示例7: hideDay
import android.widget.DatePicker; //导入方法依赖的package包/类
/**
* 隐藏日,只选择年月
*/
public void hideDay() {
if (Build.VERSION.SDK_INT >= 24) {
try {
final Field field = this.findField(DatePickerDialog.class,
DatePicker.class, "mDatePicker");
DatePicker datePicker = (DatePicker) field.get(this);
final Class<?> delegateClass = Class
.forName("android.widget.DatePicker$DatePickerDelegate");
final Field delegateField = this.findField(DatePicker.class,
delegateClass, "mDelegate");
final Object delegate = delegateField.get(datePicker);
final Class<?> spinnerDelegateClass = Class
.forName("android.widget.DatePickerSpinnerDelegate");
if (delegate.getClass() != spinnerDelegateClass) {
delegateField.set(datePicker, null);
datePicker.removeAllViews();
final Constructor spinnerDelegateConstructor = spinnerDelegateClass
.getDeclaredConstructor(DatePicker.class,
Context.class, AttributeSet.class,
int.class, int.class);
spinnerDelegateConstructor.setAccessible(true);
final Object spinnerDelegate = spinnerDelegateConstructor
.newInstance(datePicker, con, null,
android.R.attr.datePickerStyle, 0);
delegateField.set(datePicker, spinnerDelegate);
datePicker.init(year, monthOfYear, dayOfMonth, this);
datePicker.setCalendarViewShown(false);
datePicker.setSpinnersShown(true);
}
} catch (Exception e) { /* Do nothing */
}
} else {
((ViewGroup) ((ViewGroup) getDatePicker().getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
}
}
示例8: DateDialog2
import android.widget.DatePicker; //导入方法依赖的package包/类
public static void DateDialog2(final Context mContext, final TextView textView) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View v = inflater.inflate(R.layout.date_picker, null);
final DatePicker dataPicker = (DatePicker) v.findViewById(R.id.datePicker);
Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
dataPicker.init(mYear, mMonth, mDay, (datePicker, year, month, day) -> {
mYear = year;
mMonth = month;
mDay = day;
});
new MaterialDialog.Builder(mContext)
.customView(v, false)
.positiveText(android.R.string.ok)
.negativeText(android.R.string.cancel)
.onPositive((dialog, which) -> {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date lastDate = sdf.parse(mYear + "-" + (mMonth + 1) + "-" + mDay);
//得到long类型当前时间
long l = System.currentTimeMillis();
//new日期对象
Date nowDate = new Date(l);
if (beginDate == null) {
Toast.makeText(mContext, "请先选开始日期", Toast.LENGTH_SHORT).show();
} else {
if (beginDate.getTime() <= lastDate.getTime()
&& lastDate.getTime() <= nowDate.getTime()) {
textView.setText(mYear + "-" + (mMonth + 1) + "-" + mDay);
} else if (beginDate.getTime() > lastDate.getTime()) {
Toast.makeText(mContext, "结束日期必须大于开始日期", Toast.LENGTH_SHORT).show();
} else if (lastDate.getTime() > nowDate.getTime()) {
Toast.makeText(mContext, "结束日期不能大于当前日期", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}).show();
}