当前位置: 首页>>代码示例>>Java>>正文


Java DatePicker类代码示例

本文整理汇总了Java中android.widget.DatePicker的典型用法代码示例。如果您正苦于以下问题:Java DatePicker类的具体用法?Java DatePicker怎么用?Java DatePicker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DatePicker类属于android.widget包,在下文中一共展示了DatePicker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: show

import android.widget.DatePicker; //导入依赖的package包/类
public AlertDialog show(Context context) {
    dialog = new AlertDialog.Builder(context).create();
    dialog.show();
    Window window = dialog.getWindow();
    window.setContentView(R.layout.dialog_date_time);
    window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
    //window.setWindowAnimations(R.style.in_left_out_right_style);
    window.setBackgroundDrawableResource(R.color.transparent);

    datePicker = (DatePicker) window
            .findViewById(R.id.date_time_datePicker1);
    datePicker.setCalendarViewShown(false);
    timePicker = (TimePicker) window.findViewById(R.id.date_time_timePicker);
    but_ok = (Button) window.findViewById(R.id.date_time_but_ok);
    but_ok.setOnClickListener(this);
    return dialog;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:18,代码来源:DialogDate.java

示例2: onCreateDialog

import android.widget.DatePicker; //导入依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    DatePickerDialog dialog = new DatePickerDialog(getActivity(),
            R.style.CustomDatePickerDialogTheme, this, mParent.mYear, mParent.mMonth, 1);

    DatePicker datePicker = dialog.getDatePicker();

    // Limit range.
    Calendar c = mParent.getCalendar();
    datePicker.setMinDate(c.getTimeInMillis());
    c.set(Calendar.YEAR, mParent.mYear + CC_EXP_YEARS_COUNT - 1);
    datePicker.setMaxDate(c.getTimeInMillis());

    // Remove day.
    datePicker.findViewById(getResources().getIdentifier("day", "id", "android"))
            .setVisibility(View.GONE);
    return dialog;
}
 
开发者ID:googlesamples,项目名称:android-AutofillFramework,代码行数:19,代码来源:CreditCardExpirationDatePickerView.java

示例3: onCreate

import android.widget.DatePicker; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_date);
    datePicker = (DatePicker) findViewById(R.id.datePicker);
    date = datePicker.getDayOfMonth();
    month = datePicker.getMonth() +1 ;
    year = datePicker.getYear();
    Log.d("date",date+" "+month+" "+year);
    next = (Button) findViewById(R.id.next);
    next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            date = datePicker.getDayOfMonth();
            month = datePicker.getMonth() + 1;
            year = datePicker.getYear();
            Log.d("date",date+" "+month+" "+year);

            Intent i = new Intent(getApplicationContext(),Message.class);
            startActivity(i);
        }
    });


}
 
开发者ID:khalibartan,项目名称:Crammer-HITN17,代码行数:26,代码来源:SelectDate.java

示例4: showDateDialog

import android.widget.DatePicker; //导入依赖的package包/类
private void showDateDialog(final TextView textView) {
    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    DatePickerDialog dialog =
            new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                    //      birthday = new Date(i,i1,i2);
                    Date date = new Date(i - 1900, i1, i2);

                    textView.setText(formatDate(date));
                }
            }, year, month, day);
    dialog.show();

}
 
开发者ID:HowieTianDev,项目名称:ChenYan,代码行数:19,代码来源:MyInfoActivity.java

示例5: onDateSet

import android.widget.DatePicker; //导入依赖的package包/类
/** for the date selected
 * @param datePicker : the widget object for selecting a date
 * @param year : the year chosen
 * @param month : the month chosen
 * @param day : the day chosen
 * see: DatePickerFragment
 */
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
    final Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.DAY_OF_MONTH, day);

    Date date = calendar.getTime();
    Date currentDate = new Date();

    // Prevent the event's date from being a date in the future
    if (currentDate.before(date))
        date = currentDate;

    eventDate = date;
    setDateText();
}
 
开发者ID:CMPUT301F17T15,项目名称:CIA,代码行数:26,代码来源:CreateHabitEventActivity.java

示例6: onCreate

import android.widget.DatePicker; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frm_manutencao_compra_pagamentos);

    mOperacao = getIntent().getExtras().getString("Operacao");
    iCompra = getIntent().getExtras().getInt("Compra");

    if (mOperacao.matches("I"))
        setTitle(getString(R.string.i_026));

    if (mOperacao.matches("A")) {
        setTitle(getString(R.string.a_012));
    }

    edtDtPagamento = (EditText) findViewById(R.id.edtPagamento);
    edtValor = (EditText) findViewById(R.id.edtValor);
    edtObservacoes = (EditText) findViewById(R.id.edtObservacoes);

    edtDtPagamento.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int iAno = Calendar.getInstance().get(Calendar.YEAR);
            int iMes = Calendar.getInstance().get(Calendar.MONTH);
            int iDia = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

            if (edtDtPagamento.getText().toString().trim().length() != 0) {
                iDia = Integer.valueOf(edtDtPagamento.getText().toString().split("\\/")[0]);
                iMes = Integer.valueOf(edtDtPagamento.getText().toString().split("\\/")[1]) - 1;
                iAno = Integer.valueOf(edtDtPagamento.getText().toString().split("\\/")[2]);
            }

            DatePickerDialog datePickerDialog = new DatePickerDialog(frmManutencaoCompraPagamentos.this, new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar newDate = Calendar.getInstance();
                    newDate.set(year, monthOfYear, dayOfMonth);
                    edtDtPagamento.setText(Funcoes.dateFormat.format(newDate.getTime()));
                }
            }, iAno, iMes, iDia);

            datePickerDialog.show();
        }
    });

    leitura();
}
 
开发者ID:marcelohanel,项目名称:Cash,代码行数:48,代码来源:frmManutencaoCompraPagamentos.java

示例7: onCreateView

import android.widget.DatePicker; //导入依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_energy_use_bill, container, false);
    this.radioButtonFromDate = (RadioButton) view.findViewById(R.id.radioButtonFromDate);
    this.radioButtonToDate = (RadioButton) view.findViewById(R.id.radioButtonToDate);
    this.editKwhCost = (EditText) view.findViewById(R.id.editKwhCost);
    this.datePicker = (DatePicker) view.findViewById(R.id.datePicker);
    this.toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    this.setTextRadioButtonDate(radioButtonFromDate, this.fromDate);
    this.setTextRadioButtonDate(radioButtonToDate, this.toDate);
    this.setCalendarView();
    this.editKwhCost.setText(OhaHelper.getEditable(this.kwhCost));
    this.radioButtonFromDate.setOnClickListener(this);
    this.radioButtonToDate.setOnClickListener(this);
    this.datePicker.setOnClickListener(this);
    //Remover o date_picker_header do datePicker se o mesmo existir
    View viewDayDatePicker = datePicker.findViewById(Resources.getSystem().getIdentifier("date_picker_header", "id", "android"));
    if (viewDayDatePicker != null) {
        viewDayDatePicker.setVisibility(View.GONE);
    }
    this.toolbar.inflateMenu(R.menu.fragment_energy_use_bill);
    this.toolbar.setOnMenuItemClickListener(this);
    return view;
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:27,代码来源:OhaEnergyUseBillFragment.java

示例8: hidDay

import android.widget.DatePicker; //导入依赖的package包/类
/**
 * 隐藏DatePicker中的日期显示
 *
 * @param mDatePicker
 */
private void hidDay(DatePicker mDatePicker) {
    Field[] datePickerfFields = mDatePicker.getClass().getDeclaredFields();
    for (Field datePickerField : datePickerfFields) {
        if ("mDaySpinner".equals(datePickerField.getName())) {
            datePickerField.setAccessible(true);
            Object dayPicker = new Object();
            try {
                dayPicker = datePickerField.get(mDatePicker);
            } catch (Exception e) {
                mPromise.reject("-1", e);
            }
            ((View) dayPicker).setVisibility(View.GONE);
        }
    }
}
 
开发者ID:alanwyf,项目名称:react-native-double-date-picker,代码行数:21,代码来源:DoubleDatePickerDialog.java

示例9: 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();
}
 
开发者ID:liuyongfeng90,项目名称:JKCloud,代码行数:28,代码来源:DateUtil.java

示例10: timeLeftStartDateOnClickBehavior

import android.widget.DatePicker; //导入依赖的package包/类
@OnClick(R.id.time_left_from_date_content)
void timeLeftStartDateOnClickBehavior() {
    DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            startCalendar.set(Calendar.YEAR, year);
            startCalendar.set(Calendar.MONTH, monthOfYear);
            startCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            DateFormat sdf = android.text.format.DateFormat.getDateFormat(getBaseContext());
            startDateContent.setText(sdf.format(startCalendar.getTime()));
            setDate1 = true;
        }
    };
    new DatePickerDialog(this, date,
            startCalendar.get(Calendar.YEAR),
            startCalendar.get(Calendar.MONTH),
            startCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:19,代码来源:OperateTimeLeftActivityBase.java

示例11: timeLeftDueDateOnClickBehavior

import android.widget.DatePicker; //导入依赖的package包/类
@OnClick(R.id.time_left_due_date_content)
void timeLeftDueDateOnClickBehavior() {
    DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            dueCalendar.set(Calendar.YEAR, year);
            dueCalendar.set(Calendar.MONTH, monthOfYear);
            dueCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            DateFormat sdf = android.text.format.DateFormat.getDateFormat(getBaseContext());
            dueDateContent.setText(sdf.format(dueCalendar.getTime()));
            setDate2 = true;
        }
    };
    new DatePickerDialog(this, date,
            dueCalendar.get(Calendar.YEAR),
            dueCalendar.get(Calendar.MONTH),
            dueCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:19,代码来源:OperateTimeLeftActivityBase.java

示例12: taskDueDateOnClickBehavior

import android.widget.DatePicker; //导入依赖的package包/类
@OnClick(R.id.task_due_date_content)
void taskDueDateOnClickBehavior() {
    DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            dueCalendar.set(Calendar.YEAR, year);
            dueCalendar.set(Calendar.MONTH, monthOfYear);
            dueCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            DateFormat sdf = android.text.format.DateFormat.getDateFormat(getBaseContext());
            dueDateContent.setText(sdf.format(dueCalendar.getTime()));
            setDate = true;
        }
    };
    new DatePickerDialog(this, date,
            dueCalendar.get(Calendar.YEAR),
            dueCalendar.get(Calendar.MONTH),
            dueCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:19,代码来源:OperateTaskActivityBase.java

示例13: habitCalendarYearMonthOnClickBehavior

import android.widget.DatePicker; //导入依赖的package包/类
@OnClick(R.id.habit_calendar_year_month)
void habitCalendarYearMonthOnClickBehavior() {
    DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            selectedCalendar.set(Calendar.YEAR, year);
            selectedCalendar.set(Calendar.MONTH, monthOfYear);
            selectedCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            habitCalendarView.setCurrentDate(selectedCalendar.getTime());
            updateHabitCalendarYearMonth();
            updateHabitDetails(selectedCalendar.getTime());
        }
    };
    new DatePickerDialog(this.getContext(), dateListener,
            selectedCalendar.get(Calendar.YEAR),
            selectedCalendar.get(Calendar.MONTH),
            selectedCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:19,代码来源:HabitCalendarFragment.java

示例14: pickDate

import android.widget.DatePicker; //导入依赖的package包/类
/**
 * 弹出日期选择对话框
 * <p>
 * 参数:
 * title: 标题
 * datetime: 指定日期 yyyy-MM-dd
 * 返回:
 * date: 格式:yyyy-MM-dd
 */
public static void pickDate(final IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
    final String title = param.optString("title");
    String date = param.optString("datetime");
    final Calendar calendar = Calendar.getInstance();
    if (!TextUtils.isEmpty(date)) {
        calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM-dd"));
    }
    wv.post(new Runnable() {
        public void run() {
            DialogUtil.pickDate(webLoader.getPageControl().getActivity(), title, calendar, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    calendar.set(Calendar.YEAR, year);
                    calendar.set(Calendar.MONTH, monthOfYear);
                    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    String chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM-dd");
                    Map<String, Object> map = new HashMap<>();
                    map.put("date", chooseDate);
                    callback.applySuccess(map);
                }
            });
        }
    });
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:34,代码来源:UIApi.java

示例15: pickMonth

import android.widget.DatePicker; //导入依赖的package包/类
/**
 * 弹出年月选择对话框
 * <p>
 * 参数:
 * title: 标题
 * datetime: 指定日期 yyyy-MM
 * 返回:
 * month: 格式:yyyy-MM
 */
public static void pickMonth(final IQuickFragment webLoader, WebView wv, JSONObject param, final Callback callback) {
    String title = param.optString("title");
    String date = param.optString("datetime");
    final Calendar calendar = Calendar.getInstance();
    if (!TextUtils.isEmpty(date)) {
        calendar.setTime(DateUtil.convertString2Date(date, "yyyy-MM"));
    }
    DialogUtil.pickMonth(webLoader.getPageControl().getActivity(), title, calendar, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, monthOfYear);
            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            String chooseDate = DateUtil.convertDate(calendar.getTime(), "yyyy-MM");
            Map<String, Object> map = new HashMap<>();
            map.put("month", chooseDate);
            callback.applySuccess(map);
        }
    });
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:30,代码来源:UIApi.java


注:本文中的android.widget.DatePicker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。