今天看了日期选择开源项目: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();
};
}
挺好用的!!该项目使用了一个第三方jar:date4j,如果Eclipse集成需自己下载