日期和时间选择器,什么是最好(和简单)的解决方案?

Date and Time Picker, what is the best (and simple) solution?

我需要一种简单快速的方法来接受我应用程序用户的完整日期(包括小时和分钟)。我应该使用什么?我曾考虑过日期和时间选择器,但在我的 activity 布局中都使用了很多 space...谢谢。杰佛逊

正在回答您的 headline-question: 有一个android-library:better pickers。易于实施。 Time-picker 看起来像这样:

I had considered Date and Time Picker but both use to much space in my activity's layout

这是一个对话,所以它应该与你的activity-layout无关(还是我误会你了?)。

希望能帮到你:)

按照Ankur1994a给出的例子,我做了一个简单的方法来响应imageButton上的点击事件。此方法创建一个 DatePicker 对话框,然后在用户选择后创建一个时间选择器。简单高效。

public void escolheDataHoraInicio(View v) {

    // Pega a data e hora corrente
    final Calendar c = Calendar.getInstance();

    Integer mYear = c.get(Calendar.YEAR);;
    Integer mMonth = c.get(Calendar.MONTH);
    Integer mDay = c.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog datePickerDialog = new DatePickerDialog(ProvaNovaActivity.this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                String _data = dayOfMonth + "/" + (monthOfYear + 1) + "/" + year;
                _lblDataHoraInicio.setText(_data);
                TimePickerDialog timePickerDialog = new TimePickerDialog(ProvaNovaActivity.this, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        String _dataHora = _lblDataHoraInicio.getText().toString() + " " + hourOfDay + ":" + minute;
                        _lblDataHoraInicio.setText(_dataHora);
                    }
                }, 0, 0, false);
                timePickerDialog.show();
            }
        }, mYear, mMonth, mDay);
    datePickerDialog.show();

}