欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android UI日期时间选择之DateTimePicker

程序员文章站 2022-05-01 09:39:29
...
这个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  

选择小时:
Android UI日期时间选择之DateTimePicker 
            
    
    博客分类: Android  

选择分钟:
Android UI日期时间选择之DateTimePicker 
            
    
    博客分类: Android  
  • Android UI日期时间选择之DateTimePicker 
            
    
    博客分类: Android  
  • 大小: 39.7 KB
  • Android UI日期时间选择之DateTimePicker 
            
    
    博客分类: Android  
  • 大小: 34.6 KB
  • Android UI日期时间选择之DateTimePicker 
            
    
    博客分类: Android  
  • 大小: 37.9 KB