返回数组的日历事件的详细信息 [英] Return calendar event details in an array

查看:126
本文介绍了返回数组的日历事件的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如果用户选择的日期在日历,并带他到一个事件详细信息页面。在活动详细信息页面的数据显示在表格格式。到现在为止还挺好。现在的问题是如何设置在eventDetails函数的事件的细节,并返回它们设置文本

I have a calendar in which if the user selects the date and it takes him to an event details page. On the event details page the data is displayed in a tabular format. So far so good. The problem is how to set the details of the event in the eventDetails function and return them to set the text.

code:

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

字符串节日只返回一个对象。我想要得到的姓名,职务和详细信息以及相应的元素的文本设置它。我怎样才能做到这一点?如何添加姓名,职务和详细信息作为单独的对象并返回它们作为单独的对象进行相应的设置文本?我将它们添加到一个数组中?像每一个事件的时间:

The String holiday returns only one object. I want to get the name, title and details and set the corresponding element's text to it. How can I achieve this? How do I add the name, title and details as separate objects and return them as separate objects to set the text accordingly? DO I add them to an array? Something like for every event date:

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

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

If so, how do I return the array to set the text?

推荐答案

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

Create a class that contains these event details and return an instance of it. For example:

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

这篇关于返回数组的日历事件的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆