返回多个日历事件 [英] Return Multiple calendar events
问题描述
由@hmjd这里答案帮我设置多个对象的文本。不过,我现在已经运行到一个问题。一个日期可以有多个事件,我想显示所有的事件和他们相同的事件详细信息页的详细信息。我怎样才能做到这一点?
code:
公共类事件
{
公众最终字符串名称;
公共最后弦乐称号;
公共最后弦乐细节; 公共事件(最后弦乐a_name,
最后弦乐a_title,
最后弦乐a_details)
{
名称= a_name;
标题= a_title;
细节= a_details;
}
};最终事件E = eventDetails(1,4);
name.setText(e.name);
title.setText(e.title);
details.setText(e.details);//事件的详细信息
公共事件eventDetails(INT男,INT D){
开关(米){
情况1:
如果(D == 10){
返回新的事件(EVENT1,我的-TITLE1,mydetails1);
}
如果(D == 28){
返回新的事件(EVENT2,我的-TITLE1,mydetails1);
返回新的事件(EVENT3,我的-TITLE2,mydetails2); //添加在此日期另一个事件;显然这是不正确的做法。
} 打破; } 返回新的事件(default_my名2,default_my-TITLE2,default_mydetails2);
}
要存储由eventDetails返回的事件,你会做这样的事情:
的ArrayList<事件> E =新的ArrayList<事件>();
e.add(eventDetails(1,4)); //这增加了一个事件到ArrayList
然后访问存储在ArrayList中E中的活动:
事件1 = e.get(0); //第一个事件ArrayList中
事件的两个= e.get(1); ArrayList中//第二个事件
...
事件N = e.get(N); ArrayList中第n //事件
如果你想的话明确,使这个充满活力的,而不是 e.get(0)
,你会遍历ArrayList的尺寸如下:
的for(int i = 0; I< e.size();我++)
{
事件EV = e.get(ⅰ);
ev.doSomething();
ev.doSomethingElse();
}
The answer here by @hmjd helped me to set the text of multiple objects. But I have run into a problem now. A date can have multiple events and I would like to show all the events and their details on the same event details page. How can I do this?
Code:
public class Event
{
public final String name;
public final String title;
public final String details;
public Event(final String a_name,
final String a_title,
final String a_details)
{
name = a_name;
title = a_title;
details = a_details;
}
};
final Event e = eventDetails(1, 4);
name.setText(e.name);
title.setText(e.title);
details.setText(e.details);
//event details
public Event eventDetails(int m, int d) {
switch (m) {
case 1:
if (d == 10) {
return new Event("event1", "my-title1", "mydetails1");
}
if (d == 28) {
return new Event("event2", "my-title1", "mydetails1");
return new Event("event3", "my-title2", "mydetails2"); //add another event on this date; obviously this is not the right way.
}
break;
}
return new Event("default_my-name2", "default_my-title2", "default_mydetails2");
}
To store the events returned by eventDetails, you would do something like this:
ArrayList<Event> e = new ArrayList<Event>();
e.add(eventDetails(1, 4)); // This adds one event to the ArrayList
Then to access the Events stored in ArrayList e:
Event one = e.get(0); // First Event in the ArrayList
Event two = e.get(1); // Second Event in the ArrayList
...
Event n = e.get(n); // nth Event in the ArrayList
If you want to make this dynamic instead of explicitly saying e.get(0)
, you would loop over the size of the ArrayList as follows:
for (int i = 0; i < e.size(); i++)
{
Event ev = e.get(i);
ev.doSomething();
ev.doSomethingElse();
}
这篇关于返回多个日历事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!