Comments (31)
onMonthChange is called three times (when you don't scroll)
This is in the README!
Please remember that the calendar pre-loads events of three consecutive months to enable lag-free scrolling.
That's why it's being shown multiple times.
(You have to take in account the newMonth and newYear variables. They are there for a reason)
from android-week-view.
Because that WeekViewEvent constructor uses a more logical month index: januari = 1.
But you can construct it using
new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime)
@alamkanak this issue can be closed.
from android-week-view.
It's ok?
WeekViewEvent event = new WeekViewEvent(1, getEventTitle(startTime), startTime.get(Calendar.YEAR) , startTime.get(Calendar.MONTH) + 1, startTime.get(Calendar.DAY_OF_MONTH), startTime.get(Calendar.HOUR_OF_DAY), startTime.get(Calendar.MINUTE), endTime.get(Calendar.YEAR) , endTime.get(Calendar.MONTH) +1, endTime.get(Calendar.DAY_OF_MONTH), endTime.get(Calendar.HOUR_OF_DAY), endTime.get(Calendar.MINUTE));
from android-week-view.
yes, but I don't see why you don't just pass in the calendar objects. Now the calendar objects are "destructed" by you to be constructed again in the library...
from android-week-view.
new WeekViewEvent(1, getEventTitle(startTime), startTime, endTime)
that don't work, event don't show, as it should be properly?
from android-week-view.
Have you taken a look at the sample app? https://github.com/alamkanak/Android-Week-View/blob/master/sample/src/main/java/com/alamkanak/weekview/sample/MainActivity.java#L107
from android-week-view.
Yes it works, but i have timestamp and I don't know how use timestamp.
from android-week-view.
Calender start = Calender.getInstance();
start.setTimeInMillis(1421330400000)
Calender end = Calender.getInstance();
end.setTimeInMillis(1421330400000)
events.add(new WeekViewEvent(1, getEventTitle(start), startTime, endTime))
PS remember that the newMonth from the onMonthChangeListener is also 1-based instead of 0-based.
from android-week-view.
Still don't work:
Calendar start = Calendar.getInstance();
start.setTimeInMillis(1421330400000L);
Calendar end = Calendar.getInstance();
end.setTimeInMillis(1421330400000L);
events.add(new WeekViewEvent(1, getEventTitle(start), start, end));
from android-week-view.
end.setTimeInMillis(1421334000L);
You were passing in an event that last for 0 milliseconds.
from android-week-view.
14213304000 = Tue, 26 May 2420 20:00:00 GMT
from android-week-view.
I meant end.setTimeInMillis(1421334000000L);
=>
start.setTimeInMillis(1421330400000L);
end.setTimeInMillis(1421334000000L);
from android-week-view.
When i set like this:
start.setTimeInMillis(1421330400000L);
end.setTimeInMillis(1421334000000L);
my calendar view it's like this:
http://oi59.tinypic.com/4ine5c.jpg
from android-week-view.
Why when I set event like this:
@OverRide
public List onMonthChange(int newYear, int newMonth) {
List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
Calendar start = Calendar.getInstance();
start.set(Calendar.HOUR_OF_DAY, 16);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.DAY_OF_MONTH, 15);
start.set(Calendar.MONTH, 2);
start.set(Calendar.YEAR, 2015);
Calendar end = (Calendar) start.clone();
end.set(Calendar.HOUR_OF_DAY, 17);
WeekViewEvent event = new WeekViewEvent(10, getEventTitle(start), start, end);
event.setColor(getResources().getColor(R.color.event_color_03));
events.add(event);
return events;
}
calendar views like this:
http://oi59.tinypic.com/10saihc.jpg
from android-week-view.
so I do not think it should be?
from android-week-view.
I really do not know how I set the event for example 15-01-2015. So that two months after scrolling forward and return to the event, was displayed only once?
from android-week-view.
just only add it if newMonth==1 and newYear==2015
from android-week-view.
This is a bad idea, because I have list with dates, ie: 15-01-2015, 23-03-2015, 07-06-2015...and I have set all dates.
from android-week-view.
This seriously doesn't belong in an issue for this library.
Just only add the events which have a matching month and year (matching = event falls in the month that is requested by newMonth and newYear: event.getMonth() == newMonth && event.getYear() == newYear). That's what I am saying.
When you scroll, eventually the right month will be requested and the event will be loaded.
from android-week-view.
Please show me example.
from android-week-view.
Remember this is pseudo-code, not real java code
weekviewEvents = new ArrayList()
for(Event event : allEvents){
if(event.getMonth() == newMonth && event.getYear() == newYear){
weekviewEvents.add(event)
}
}
return weekviewEvents
from android-week-view.
This is my code, event don't show:
List events = new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
// Get a reference for the week view in the layout.
mWeekView = (WeekView) findViewById(R.id.weekView);
DateTimeInterpreter dateTimeInterpreter = new DateTimeInterpreter() {
@Override
public String interpretDate(Calendar calendar) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
return simpleDateFormat.format(calendar.getTime());
}
@Override
public String interpretTime(int i) {
return String.valueOf(i + ":00");
}
};
mWeekView.setDateTimeInterpreter(dateTimeInterpreter);
mWeekView.setOnEventClickListener(this);
mWeekView.setMonthChangeListener(this);
mWeekView.setNumberOfVisibleDays(1);
// Lets change some dimensions to best fit the view.
mWeekView.setColumnGap((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
mWeekView.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
mWeekView.setEventTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics()));
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
startTime.setTimeInMillis(1421506800 * 1000L);
endTime.setTimeInMillis(1421510400 * 1000L);
WeekViewEvent event = new WeekViewEvent(1, "fddsdsdsd", startTime, endTime);
event.setColor(getResources().getColor(R.color.event_color_01));
events.add(event);
}
@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
List<WeekViewEvent> weekviewEvents = new ArrayList<WeekViewEvent>();
for (WeekViewEvent event : events) {
if(event.getStartTime().get(Calendar.MONTH) == newMonth && event.getStartTime().get(Calendar.YEAR) == newYear){
weekviewEvents.add(event);
}
}
return weekviewEvents;
}
from android-week-view.
How many times do I need to say that newMonth is 1-based and Calendar is 0-based?
=> event.getStartTime().get(Calendar.MONTH)+1 == newMonth
from android-week-view.
Sorry my fault, now i have that code:
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
startTime.setTimeInMillis(1421506800 * 1000L);
endTime.setTimeInMillis(1421510400 * 1000L);
WeekViewEvent event = new WeekViewEvent(1, "first event", startTime, endTime);
event.setColor(getResources().getColor(R.color.event_color_01));
events.add(event);
startTime.setTimeInMillis(1421596800 * 1000L);
endTime.setTimeInMillis(1421600400 * 1000L);
event = new WeekViewEvent(1, "second event", startTime, endTime);
event.setColor(getResources().getColor(R.color.event_color_01));
events.add(event);
}
@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
List<WeekViewEvent> weekviewEvents = new ArrayList<WeekViewEvent>();
for (WeekViewEvent event : events) {
if(event.getStartTime().get(Calendar.MONTH)+1 == newMonth && event.getStartTime().get(Calendar.YEAR) == newYear){
weekviewEvents.add(event);
}
}
return weekviewEvents;
}
and my calendar look like this
http://oi57.tinypic.com/14xz790.jpg
from android-week-view.
I'm guessing you should pass in a different id for the second event...
from android-week-view.
I change id and doesn't work.
from android-week-view.
you have to create new instances of the Calendar object (startTime, endTime) for your second event, otherwise you change the time of the first event too.
from android-week-view.
Yes, caske33's answer is right. I had a similar problem and I lost about half day of work to resolve it.
Btw i don't understand why this API preloads 3 months events.
You must add your events by matching your actual month and year with nextMonth and nextYear variables of onMonthChange for avoiding the creations of duplicate events, but in this way you lose the benefit of the 3 months preload.
So probably it's better adding the matching also for your previous and following month events, but in this case you have again the "duplicate events problem".
from android-week-view.
The reason why there's a 3 month preload is to smooth the swiping. This way the library won't have to wait for you to provide the events when the user scrolls to the next month, they will already be loaded.
And most people don't match all their events with the nextMonth and nextYear variables but they load their events based on those variables (e.g. they look in the database for the events that fall within the month requested)
from android-week-view.
Thank you, i undestand.
from android-week-view.
Answer from @caske33 is correct
from android-week-view.
Related Issues (20)
- How to show the event that starts at Today 11PM and ends at Tomorrow morning 5AM HOT 1
- Accessibility/Talkback implementation of WeekView and its Events
- How to navigate to particular date HOT 1
- How can I hide or clear the header area?
- How to use this in Kotlin project? HOT 1
- Unable to display events
- Auto scroll to current hour?
- use firebase with Android-week-View HOT 2
- Events issue
- Name of event is repeated 3 times HOT 1
- Using a deprecated clipRect() in 1.2.6 HOT 2
- How to add new column in Day View?
- AAPT: error: duplicate value for resource 'attr/textStyle' with config ''.
- Is there a recent Kotlin Sample I can see to understand how this code is implemented HOT 2
- How can we change the **todayHeaderText** date format
- Is it possible to add event in normal date format?
- Is it possible to highlight weekends?
- Need to use Android X as its conflicting dependencies with recent android version
- Change X-axis and y-axis, and vertical scrolling to specific range
- Not integrated Lib
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-week-view.