當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。