android 日历

[1].[代码] [Java]代码 跳至
[1]

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

//读取日历事件
    public static
void getCalendarInfo(Activity activity,String tag){

        String[] projection =
new String[]{CalendarContract.Events._ID,CalendarContract.Events.TITLE};

        ContentResolver cr = activity.getContentResolver();

        Cursor cursor = cr.query(CalendarContract.Events.CONTENT_URI, projection,
null, null,
null);

        int
idIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events._ID);

        Log.d(tag, cursor.getCount()+"");

        int
titleIndex = cursor.getColumnIndexOrThrow(CalendarContract.Events.TITLE);

        while
(cursor.moveToNext()) {

           
String id = cursor.getString(idIndex);

           
String title = cursor.getString(titleIndex);

           
Log.d(tag, id+":"+title);

       
}

       
cursor.close();

    }

    

    //插入事件
    public static
void addCalendarEvent(Activity activity,String tag){

       
Intent intent = new
Intent(Intent.ACTION_INSERT,CalendarContract.Events.CONTENT_URI);

       
Log.d(tag, CalendarContract.Events.CONTENT_URI.toString());

       
intent.putExtra(CalendarContract.Events.TITLE, "Launch");

       
intent.putExtra(CalendarContract.Events.DESCRIPTION,
"Launch,Android app");

       
intent.putExtra(CalendarContract.Events.EVENT_LOCATION,
"baidu.com");

       
Calendar calendar = Calendar.getInstance();

       
calendar.setTime(new
Date());

       
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calendar.getTimeInMillis());

       
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY,
true);

       
activity.startActivity(intent);

    }

    //编辑日历事件
    public static
void editCalendarEvent(Activity activity,String tag){

       
long rowId = 1;

       
Uri editUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI,rowId);

       
Log.d(tag, CalendarContract.Events.CONTENT_URI.toString());

       
Intent intent = new
Intent(Intent.ACTION_EDIT,editUri);

       
intent.putExtra(CalendarContract.Events.EVENT_LOCATION,
"NJ");

       
Calendar calendar = Calendar.getInstance();

       
calendar.set(2015,
2, 17,
12, 1,
1);

       
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calendar.getTimeInMillis());

       
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY,
true);

       
activity.startActivity(intent);

    }

    //查看日历
    public static
void viewCalendar(Activity activity,String tag){

       
Calendar calendar = Calendar.getInstance();

       
calendar.set(2015,
2, 17,
12, 1,
1);

       
Uri uri = Uri.parse("content://com.android.calendar/time/"+calendar.getTimeInMillis());

       
Intent intent = new
Intent(Intent.ACTION_VIEW,uri);

       
activity.startActivity(intent);

    }

时间: 2024-08-05 07:08:48

android 日历的相关文章

android 日历图标显示星期

上一篇文档中谈到了在日历图标上显示当前日期, 现在我添加了几行代码,可以在日历图标上显示对应的星期: 修改源码是在Utilities.java中 函数createCalendarIconBitmap 添加几行代码: int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); String weekStrings[] = {"周日","周一","周二","周三&quo

Android日历视图(CalendarView)讲解-android学习之旅(三十六)

CalendarView简介 CalendarView用于显示和选择日期,如果希望监听事件的改变可以用setOnDateChangeListener()方法. CalendarView属性介绍 代码示例 package peng.liu.test; import android.app.Activity; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bund

Android日历开发之右上角标注红点事件

1.效果如下所示: 2.方法:      前提:已经知道如何在右上角画圆点的情况下.      这是一个任务显示器,每个任务都有一个时间,比如2014.01.12.      如果要标注2016.08月所有有任务的时间,就需要在数据库中去查询,此时用like语句就可以了:      如:select * from db where dtime like '2014.08.%';      然后,再在对应的控制层做处理.

android自定义日历的使用方法

子夜枯灯123提供了一个自定义的android日历,他的博客地址如下: http://blog.csdn.net/huangyanbin123/article/details/38350213 他提供的代码除了自定义日历外,还有一个demo,对于大部分人来说,仅仅需要展示一个日历,并响应日历的click事件即可.因此我简化了他的demo,给出了一个更加简单的demo和使用方法,方法分为三步: 第一步:导入 http://download.csdn.net/detail/huangyanbin12

Android自定义可标记日历

"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Android自定义可标记日历 - 会飞的徐公明 - 博客频道 - CSDN.NET 会飞的徐公明 目录视图 摘要视图 订阅 [活动]2017 CSDN博客专栏评选 &nbsp [5月书讯]流畅的Python,终于等到你!    &nbsp CSDN日报201

Android自带CalendarView类实现日历视图

文章由来:学习一下日历控件的实现,Android3.0以下的版本请查阅其他文章. 本文主要是介绍Android日历视图控件CalendarView相关的内容,然后在后面会给出一个简单的Demo. CalendarView继承自FrameLayout 其他文章都引用的类似的java代码示例如下: public class MainActivity extends Activity implements OnClickListener, OnDateChangeListener { private

优秀的 Android 开源项目

摘要  转载http://www.trinea.cn/android/android-open-source-projects-view/,方便大家找到自己合适的资料 目录[-] 一.ListView 二.ActionBar 三.Menu 四.ViewPager .Gallery 五.GridView 六.ImageView 七.ProgressBar 八.其他 GitHub上优秀Android开源项目 3. Android开发神器 1.Xabber客户端 2.oschina客户端 3.手机安全

2016年最牛逼的分类Android项目源码免费一次性打包下载!

之前发过一个帖子,但是那个帖子有点问题我就重新发一个吧,下面的源码是我从今年开始不断整理源码区和其他网站上的安卓例子源码,目前总共有810套左右,根据实现的功能被我分成了100多个类,总共接近2.5G,还在不断更新.初学者可以快速方便的找到自己想要的例子,大神也可以看一下别人的方法实现.虽然的例子都是我一个人辛辛苦苦花了很多时间和精力整理的,但是既然这些例子是来自于社区那就让他们免费回归社区吧,(是的!特么的不要一分钱!最看不起那些挂羊头卖狗的)你可以在本帖里面按Ctrl+F查找你需要的关键字,

GitHub 优秀的 Android 开源项目

转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介绍那些不错个性化的View,包含ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar及其它如Dialog.Toast.EditText.TableView.Activity Animation等等. 一.ListView android-pulltorefresh 一个强大的拉动