如何在android上创建简单的日历
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10977422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create simple calendar on android
提问by Croatia Boy
I need simple calendar for my android application, in which I can pick a date from it, and read data from database based on picked date. I'm having trouble finding good and simple example of calendar. Does anybody have a source code of simple calendar? Thanks!
我的 android 应用程序需要一个简单的日历,我可以从中选择一个日期,并根据选择的日期从数据库中读取数据。我很难找到好的和简单的日历示例。有人有简单日历的源代码吗?谢谢!
回答by Pattabi Raman
Checkout these links with source code example, you'll get an idea about it:
使用源代码示例查看这些链接,您将了解它:
Android-Calendar-GridView-Adapter
Android-Calendar-GridView-Adapter
回答by Pattabi Raman
The Calendar API is available as of Android 4.0.
日历 API 从 Android 4.0 开始可用。
Creating new events is done via Intents and does not require any permission. Setting properties of the event is done via Intent extras. The user will be prompted if the event should be created.
创建新事件是通过 Intent 完成的,不需要任何许可。设置事件的属性是通过 Intent extras 完成的。将提示用户是否应创建事件。
For example the following will prompt the user if an event should be created with certain details.
例如,以下将提示用户是否应创建具有某些详细信息的事件。
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(intent);
You can also add dates and time, if this event is repeated and the like. See the comments in the coding for examples.
您还可以添加日期和时间,如果此事件重复等。有关示例,请参阅编码中的注释。
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(Events.TITLE, "Learn Android");
intent.putExtra(Events.EVENT_LOCATION, "Home suit home");
intent.putExtra(Events.DESCRIPTION, "Download Examples");
// Setting dates
GregorianCalendar calDate = new GregorianCalendar(2012, 10, 02);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calDate.getTimeInMillis());
// Make it a full day event
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
// Make it a recurring Event
intent.putExtra(Events.RRULE, "FREQ=WEEKLY;COUNT=11;WKST=SU;BYDAY=TU,TH");
// Making it private and shown as busy
intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
More about this article
关于这篇文章的更多信息
and more calendar api tutorials
以及更多日历 API 教程
Here is another good simple calender exampletutorials.
这是另一个很好的简单日历示例教程。
回答by rajeesh
Here is a sample calendar app you can go through. http://droidwalk.blogspot.in/2012/11/android-calendar-sample.html#more
这是您可以浏览的示例日历应用程序。 http://droidwalk.blogspot.in/2012/11/android-calendar-sample.html#more
回答by Prativa Neupane
You should use a DatePicker... Because that's the only simple way through which users can pick a date and read data from a database based on that date... But hey you should also show your effort...
您应该使用 DatePicker... 因为这是用户可以选择日期并根据该日期从数据库中读取数据的唯一简单方法...但是,嘿,您还应该展示您的努力...