android - 非 Activity 类中的运行时 DatePicker

标签 android android-2.2-froyo

我们可以从 android 中的非 Activity 类创建运行时日期选择器对话框吗?

最佳答案

为了创建任何dialog,您需要传递context(您可以通过构造函数或通过任何函数参数传递)

然后创建一个日期选择器对话框

 Calendar c = Calendar.getInstance();//To initialize with the current date 
            int mYear = c.get(Calendar.YEAR);
            int mMonth = c.get(Calendar.MONTH);
            int mDay = c.get(Calendar.DAY_OF_MONTH);

        DatePickerDialog dialog= new DatePickerDialog(context, mDateSetListener,
                       mYear, mMonth, mDay);
        dialog.show();

关于android - 非 Activity 类中的运行时 DatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6702723/

相关文章:

java - android从getintent中删除数据

android - 如何自定义 PreferenceActivity 的标题?

javascript - JavascriptInterface在版本> 2.1上不起作用

android - 如何在不显示设备默认电子邮件表单的情况下直接从 android 应用程序发送电子邮件?

android - Xamarin Android 中的可见性转换器

android - 移动图像按钮后,应用程序崩溃!安卓

android - 更新到 Froyo 后无法使用 adb cd do sdcard

android - body scrollLeft 与 Android 2.x

android - 在固定时间间隔后调用特定方法

android - React-Native android NDK