标签:android日期选择 时间选择
今天看了日期选择开源项目:https://github.com/roomorama/Caldroid
效果图:
开源项目用的是Studio 开发的 ,如果用Eclipse自己手动导入就可以了,常用的方法:
public static SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy");
Button showDialogButton = (Button) findViewById(R.id.show_dialog_button); showDialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Setup caldroid to use as dialog dialogCaldroidFragment = new CaldroidFragment(); dialogCaldroidFragment.setCaldroidListener(getListener()); Bundle state = savedInstanceState; final String dialogTag = "CALDROID_DIALOG_FRAGMENT"; if (state != null) { dialogCaldroidFragment.restoreDialogStatesFromKey( getSupportFragmentManager(), state, "DIALOG_CALDROID_SAVED_STATE", dialogTag); Bundle args = dialogCaldroidFragment.getArguments(); if (args == null) { args = new Bundle(); dialogCaldroidFragment.setArguments(args); } } else { // Setup arguments Bundle bundle = new Bundle(); // Setup dialogTitle dialogCaldroidFragment.setArguments(bundle); } dialogCaldroidFragment.show(getSupportFragmentManager(), "CALDROID_DIALOG_FRAGMENT"); } });
protected CaldroidListener getListener() { // TODO Auto-generated method stub return new CaldroidListener() { @Override public void onSelectDate(Date date, View view) { // TODO Auto-generated method stub dialogCaldroidFragment.dismiss(); Toast.makeText(getApplicationContext(), formatter.format(date),Toast.LENGTH_SHORT).show(); }; }
标签:android日期选择 时间选择
原文地址:http://blog.csdn.net/anddroid_lanyan/article/details/41446423