将事件添加并保存到android中的自定义日历

时间:2015-05-19 16:08:46

标签: java android calendar

我在Android上工作自定义日历。我在github上找到了日历的源代码,并且已根据我的需要修改它。但是,我无法弄清楚如何将事件添加到日历中,甚至无法将某些内容保存到特定的gridcell。

我想要发生的是,当用户持有gridcell时,应该在新活动中显示已经过scedueled的概述。但我的问题是我不知道如何将信息保存到特定的gridcell(日期)。

我迫切需要建议。

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            LayoutInflater inflater = (LayoutInflater) _context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.screen_gridcell, parent, false);
        }


        gridcell = (Button) row.findViewById(R.id.calendar_day_gridcell);
        gridcell.setOnClickListener(this);


        Log.d(tag, "Current Day: " + getCurrentDayOfMonth());
        String[] day_color = list.get(position).split("-");
        final String theday = day_color[0];
        String themonth = day_color[2];
        String theyear = day_color[3];
        if ((!eventsPerMonthMap.isEmpty()) && (eventsPerMonthMap != null)) {
            if (eventsPerMonthMap.containsKey(theday)) {
                num_events_per_day = (TextView) row
                        .findViewById(R.id.num_events_per_day);
                Integer numEvents = (Integer) eventsPerMonthMap.get(theday);
                num_events_per_day.setText(numEvents.toString());
            }
        }
        gridcell.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                Intent intent = new Intent(MyCalendarActivity.this, DayOverview.class);
                startActivity(intent);
                return false;
            }
        });

        gridcell.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                long dayInInteger = getItemId(position);
                getCurrentDayOfMonth();
                yearToAddToEvent = Integer.toString(year);
                monthToAddToEvent = currentMonthName;
                dayToAddToEvent = theday;
                Toast.makeText(getApplicationContext(), yearToAddToEvent + monthToAddToEvent + dayToAddToEvent, Toast.LENGTH_LONG).show();


                Intent intent = new Intent(MyCalendarActivity.this, AddEvent.class);
                intent.putExtra("id",getItemId(position));
                startActivity(intent);
            }
        });

        Bundle bundle = getIntent().getExtras();

        if (bundle != null) {
            String hour = bundle.get("hour").toString();
            String minute = bundle.get("minute").toString();
            String event = bundle.get("event").toString();


            colorSet = true;

        }



            gridcell.setText(theday);
            gridcell.setTag(theday + "-" + themonth + "-" + theyear);
            Log.d(tag, "Setting GridCell " + theday + "-" + themonth + "-"
                    + theyear);

            if (day_color[1].equals("GREY")) {
                gridcell.setTextColor(getResources()
                        .getColor(R.color.lightgray));
            }
            if (day_color[1].equals("WHITE")) {
                gridcell.setTextColor(getResources().getColor(
                        R.color.dark));
            }
            if (day_color[1].equals("BLUE")) {
                gridcell.setTextColor(getResources().getColor(R.color.orrange));
            }

            return row;


        }

0 个答案:

没有答案