将自定义日期设置为 Android 日历
我正在创建一个应用程序,并试图让日历功能正常工作。到目前为止,事件已添加,但我无法获得正确的自定义日期。我相信这可能是格式,但我正在努力使其正确。
我得到的代码如下:
@Override
public void onItemClick(AdapterView<?> adp, View v, int position, long id)
{
FixtureSupport fixture = (FixtureSupport) adapter.getItem(position);
try
{
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = (Date)formatter.parse("10/05/2012");
Intent event = new Intent(Intent.ACTION_EDIT);
event.setType("vnd.android.cursor.item/event");
event.putExtra("title", "Rugby Match");
event.putExtra("description", fixture.getHome() + " V " + fixture.getAway());
event.putExtra("eventLocation", fixture.getVenue());
event.putExtra("hasAlarm", 1);
event.putExtra("startTime", date);
startActivity(event);
}
catch (Exception e)
{
System.err.println("Error");
}
}
当我单击屏幕上的项目时,标题/描述/位置都有效。但是当我尝试设置 startTime (事件日期)时,它不起作用。目前,当我创建一个明天开始的活动时,它说该活动将在一分钟后开始!
帮助将不胜感激,谢谢大家!
I am creating an app and I am trying to get the calendar functionality working properly. So far the event gets added but I cannot get the custom date correct. I believe it may be the format but I am struggling to get that correct.
The code I got is the following:
@Override
public void onItemClick(AdapterView<?> adp, View v, int position, long id)
{
FixtureSupport fixture = (FixtureSupport) adapter.getItem(position);
try
{
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = (Date)formatter.parse("10/05/2012");
Intent event = new Intent(Intent.ACTION_EDIT);
event.setType("vnd.android.cursor.item/event");
event.putExtra("title", "Rugby Match");
event.putExtra("description", fixture.getHome() + " V " + fixture.getAway());
event.putExtra("eventLocation", fixture.getVenue());
event.putExtra("hasAlarm", 1);
event.putExtra("startTime", date);
startActivity(event);
}
catch (Exception e)
{
System.err.println("Error");
}
}
When I click the item on the screen, the title / description / location all work. But when I try and set the startTime (date of the event) it will not work. Currently when I create a event thats meant to be starting tomorrow, it says the event will begin in 1minute!
Help will be appreciated, thanks guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过:
当您访问传递的变量时:
Did you try:
And when you are accessing passed variables: