gpt4 book ai didi

java - 以数组形式返回日历事件详细信息

转载 作者:行者123 更新时间:2023-12-01 15:17:51 24 4
gpt4 key购买 nike

我有一个日历,如果用户在其中选择日期,则会将他带到事件详细信息页面。在事件详细信息页面上,数据以表格格式显示。到目前为止,一切都很好。问题是如何在eventDetails函数中设置事件的详细信息并返回它们来设置文本。

代码:

  //get the data and split it
String[] dateAr = date_string.split("-|\\||\\(|\\)|\\s+");
m = Integer.parseInt(dateAr[6]);
d = Integer.parseInt(dateAr[3]);
y = Integer.parseInt(dateAr[8]);

name = (TextView) this.findViewById(R.id.name);
title = (TextView) this.findViewById(R.id.title);
details = (TextView) this.findViewById(R.id.details);


name.setText(name_details); //should get the info from the eventDetails method
title.setText(title_details); //should get the info from the eventDetails method
details.setText(event_details); //should get the info from the eventDetails method

//event details
public String eventDetails(int m, int d) {
String holiday = "";
switch (m) {
case 1:
if (d == 1) {
holiday = "Some event";
} else if (d == 10) {
holiday = "Some event";
}
break;
case 3:
if ((d == 11) || (d == 12)) {
holiday = "Some event";
}
break;
case 7:
if ((d == 1) && (d== 7)) {
holiday = "Some event";
}
break;
}

return holiday;
}

字符串holiday仅返回一个对象。我想获取名称、标题和详细信息,并将相应元素的文本设置为其。我怎样才能实现这个目标?如何将名称、标题和详细信息添加为单独的对象,并将它们作为单独的对象返回以相应地设置文本?我要把它们添加到数组中吗?每个事件日期类似:

String holiday[] = {"name of the event", "title of the event", "details of the event"};

如果是这样,我如何返回数组来设置文本?

最佳答案

创建一个包含这些事件详细信息的并返回它的实例。例如:

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;
}
};

public Event eventDetails(int m, int d) {
if (some-condition)
return new Event("my-name1", "my-title1", "mydetails1");
else
return new Event("my-name2", "my-title2", "mydetails2");
}

final Event e = eventDetails(1, 4);
name.setText(e.name);
title.setText(e.title);
details.setText(e.details);

关于java - 以数组形式返回日历事件详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11386650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com