Android Week View(alamkanak-库)将事件名称重复三份 [英] Android Week View (alamkanak - library) triplicates event names

查看:50
本文介绍了Android Week View(alamkanak-库)将事件名称重复三份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好。

我遇到了这个问题,当我在日历中添加一些事件时,它会将当时的名称加倍。

I have this problem, when i add some events to my calendar it triplicates the names of then.

我尝试更改名称,事件时间,没有任何效果。

i tried changing the name, the time of the events, nothing worked.

请大家帮帮我。

查看应用img

此处是我的代码

package com.example.admin.myapplication;

import android.graphics.RectF;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import com.alamkanak.weekview.WeekView;
import com.alamkanak.weekview.WeekViewEvent;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class WeekView_class extends ActionBarActivity implements          WeekView.MonthChangeListener, WeekView.EventClickListener, WeekView.EventLongPressListener{
WeekView mWeekView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_week_view);

    // Get a reference for the week view in the layout.
    mWeekView = (WeekView) findViewById(R.id.weekView);

    // Set an action when any event is clicked.
    mWeekView.setOnEventClickListener(this);

    // The week view has infinite scrolling horizontally. We have to provide the events of a
    // month every time the month changes on the week view.
    mWeekView.setMonthChangeListener(this);
    // Set long press listener for events.
    mWeekView.setEventLongPressListener(new WeekView.EventLongPressListener() {
        @Override
        public void onEventLongPress(WeekViewEvent event, RectF eventRect) {

        }
    });
    /*Calendar cal = Calendar.getInstance();
    cal.set(2015, 5 - 1, 30, 12, 00);
    mWeekView.goToDate(cal);*/
    mWeekView.setNumberOfVisibleDays(5);
    mWeekView.setColumnGap((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));//espacio entre columnas
    mWeekView.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10, getResources().getDisplayMetrics()));//tamanho de letra de la api
    mWeekView.setEventTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, getResources().getDisplayMetrics()));//tamanho de lettra del evento
    mWeekView.setEventPadding((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()));



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_week_view, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    // Populate the week view with some events.
    List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();

    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.DAY_OF_MONTH, 19);
    startTime.set(Calendar.HOUR_OF_DAY, 1);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, 10);
    startTime.set(Calendar.YEAR, 2015);
    Calendar endTime = (Calendar) startTime.clone();
    endTime.set(Calendar.DAY_OF_MONTH, 19);
    endTime.set(Calendar.HOUR_OF_DAY, 5);
    endTime.set(Calendar.MINUTE, 0);
    endTime.set(Calendar.MONTH, 10);
    endTime.set(Calendar.YEAR, 2015);
    WeekViewEvent event = new WeekViewEvent(0, "Epoca", startTime, endTime);
    event.setColor(getResources().getColor(R.color.orange));
    events.add(event);


    startTime = Calendar.getInstance();
    startTime.set(2015, 10, 19, 6, 00);
    endTime = Calendar.getInstance();
    endTime.set(2015, 10, 19, 9, 00);
    WeekViewEvent event2 = new WeekViewEvent(0,"00kjbhjbhjbjbhj",startTime, endTime);
    event2.setColor(getResources().getColor(R.color.orange));
    events.add(event2);


    return events;
}

@Override
public void onEventClick(WeekViewEvent weekViewEvent, RectF rectF) {
    Toast.makeText(this, weekViewEvent.getName().toString()+"\ncon actuacion especial de\n bagulho \nde sao paulo",Toast.LENGTH_SHORT).show();
}

@Override
public void onEventLongPress(WeekViewEvent weekViewEvent, RectF rectF) {

}
private String getEventTitle(Calendar time) {
    return String.format("Event of %02d:%02d %s/%d", time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE), time.get(Calendar.MONTH)+1, time.get(Calendar.DAY_OF_MONTH));
}
}

谢谢你们!

推荐答案

请在您的代码中添加以下代码段,以一次显示单个事件

Please add below snippet in your code for display single event at a time

weekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() {
        @Override
        public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
            if (newMonth == mainCalendar.get(Calendar.MONTH))
                return events;
            else {
                return new ArrayList<WeekViewEvent>();
            }
        }
    });

我在这里按月份检查。如果特定事件属于该月,则仅返回事件数组,否则返回空数组:)

Here I am checking by month . If particular event belong to that month , than only return event array otherwise return empty array :)

快乐编码。

这篇关于Android Week View(alamkanak-库)将事件名称重复三份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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