Android UI日期时间选择之DateTimePicker

阅读更多
这个DateTimePicker提供了Google Agenda app的日期时间选择器,非常漂亮。

https://github.com/flavienlaurent/datetimepicker

***依赖于NineOldAndroids https://github.com/JakeWharton/NineOldAndroids

import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.fourmob.datetimepicker.date.DatePickerDialog.OnDateSetListener;
import com.sleepbot.datetimepicker.time.RadialPickerLayout;
import com.sleepbot.datetimepicker.time.TimePickerDialog;

public class MainActivity extends FragmentActivity implements OnDateSetListener, TimePickerDialog.OnTimeSetListener {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_date_time_picker_sample);

        final Calendar calendar = Calendar.getInstance();
        final DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), false);
        final TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(this, calendar.get(Calendar.HOUR_OF_DAY) ,calendar.get(Calendar.MINUTE), false, false);

        findViewById(R.id.button_date).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                datePickerDialog.show(getSupportFragmentManager(), "datepicker");
            }
        });
        
        findViewById(R.id.button_time).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            	 timePickerDialog.show(getSupportFragmentManager(), "timepicker");
            }
        });
    }

    @Override
    public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
        ((TextView) findViewById(R.id.date_text)).setText(year + "/" + (month + 1) + "/" + day);
    }

	@Override
	public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
		((TextView) findViewById(R.id.time_text)).setText(hourOfDay + ":" + minute);
	}

}


日期选择:
Android UI日期时间选择之DateTimePicker_第1张图片

选择小时:
Android UI日期时间选择之DateTimePicker_第2张图片

选择分钟:
Android UI日期时间选择之DateTimePicker_第3张图片
  • DateTimePickerSample.zip (838.9 KB)
  • 下载次数: 307
  • Android UI日期时间选择之DateTimePicker_第4张图片
  • 大小: 39.7 KB
  • Android UI日期时间选择之DateTimePicker_第5张图片
  • 大小: 34.6 KB
  • Android UI日期时间选择之DateTimePicker_第6张图片
  • 大小: 37.9 KB
  • 查看图片附件

你可能感兴趣的:(Android UI日期时间选择之DateTimePicker)