【发布时间】:2012-07-08 20:57:24
【问题描述】:
我有一个日历,如果用户在其中选择日期,它会将他带到活动详细信息页面。在事件详细信息页面上,数据以表格格式显示。到目前为止,一切都很好。问题是如何在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"};
如果是这样,我如何返回数组来设置文本?
【问题讨论】: