我正在尝试将事件添加到日历中,我有一个自定义日历,如果我想添加事件,我将单击日期网格并打开手机内置日历以添加事件,我面临的问题是日历打开以添加显示当前日期的事件,自动填充它,即使我单击其他日期。如何获取我在添加事件日历中单击的日期。
gridview.setOnItemClickListener(new OnItemClickListener() {
@SuppressLint("NewApi") public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
desc = new ArrayList<String>();
date = new ArrayList<String>();
((CalendarAdapter) parent.getAdapter()).setSelected(v);
String selectedGridDate = CalendarAdapter.dayString
.get(position);
String[] separatedTime = selectedGridDate.split("-");
String gridvalueString = separatedTime[2].replaceFirst("^0*",
"");// taking last part of date. ie; 2 from 2012-12-02.
int gridvalue = Integer.parseInt(gridvalueString);
// navigate to next or previous month on clicking offdays.
if ((gridvalue > 10) && (position < 8)) {
setPreviousMonth();
refreshCalendar();
} else if ((gridvalue < 7) && (position > 28)) {
setNextMonth();
refreshCalendar();
}
((CalendarAdapter) parent.getAdapter()).setSelected(v);
for (int i = 0; i < Utility.startDates.size(); i++) {
if (Utility.startDates.get(i).equals(selectedGridDate)) {
desc.add(Utility.nameOfEvent.get(i));
}
}
if (desc.size() > 0) {
for (int i = 0; i < desc.size(); i++) {
// set some properties of rowTextView or something
rowTextView.setText("Event on: "+selectedGridDate +": " + desc.get(i));
//rowTextView.setTextColor(Color.BLUE);
// final ListView listView = (ListView) view.findViewById(R.id.list);
quickAction.show(v);
}
}else {
/**
* Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.addeventdialog);
dialog.setTitle("Events");
TextView showdate = (TextView) dialog.findViewById(R.id.showdate);
showdate.setText(selectedGridDate);
dialog.show(); */
Calendar cal = Calendar.getInstance();
GregorianCalendar calDate = new GregorianCalendar();
if (Build.VERSION.SDK_INT >= 14) {
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,calDate.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,calDate.getTimeInMillis())
.putExtra(Events.TITLE, "Yoga")
.putExtra(Events.DESCRIPTION, "Group class")
.putExtra(Events.EVENT_LOCATION, "The gym")
.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
.putExtra(Intent.EXTRA_EMAIL, "rowan@example.com,trevor@example.com");
startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", false);
intent.putExtra("rrule", "FREQ=DAILY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app");
startActivity(intent);
}
}
desc = null;
}
});
return view;
}
任何帮助表示赞赏。