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

选择小时:
Android UI日期时间选择之DateTimePicker

选择分钟:
Android UI日期时间选择之DateTimePicker

你可能感兴趣的:(datetimepicker)