Problem to select day after current day
I'm having trouble selecting day after the current day. For example: 04/26/2017, I can select, but the next day, 04/27/2017, I can not. I'll only be able to select 3 or 4 days after the current one.
What version are you using? What phone are you debugging with? Can I also see your xml layout file?
Version: lastest (2.0.1)
Phone: Moto G3
XML: I just using the calendar:
<com.github.sundeepk.compactcalendarview.CompactCalendarView android:id="@+id/cvMonth" android:layout_width="match_parent" android:layout_height="250dp" android:layout_marginTop="10dp" android:paddingLeft="10dp" android:paddingRight="10dp" app:compactCalendarBackgroundColor="@android:color/transparent" app:compactCalendarCurrentDayBackgroundColor="@android:color/transparent" app:compactCalendarCurrentSelectedDayBackgroundColor="@color/colorAccent" app:compactCalendarMultiEventIndicatorColor="#fff" app:compactCalendarTargetHeight="250dp" app:compactCalendarTextColor="@color/colorPrimaryText" app:compactCalendarShouldSelectFirstDayOfMonthOnScroll="true" app:compactCalendarTextSize="12sp" />
Can I suggest you download the project. I has a sample app. If you can debug that app, can you replicate the same problem?
I'll try with the sample app.
With the sample, I dont have this problem. I'll compare my code with your code and try again. Thanks!
To click on the day, I have to use this method, right?
compactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
}
});
To click on the day, you just need to tap on it and then to receive a callback as to what day was click you use the CompactCalendarViewListener as you have already done so. Should be simple as that.
I already did that, but doesn't work properly. On your sample app works, but on my app doesn't.
Is it possible to show me some code on how you are using the library?
Call<ArrayList<ObjectivesReturn>> call = mApiInterface.getApplicationsYearMonth(user_id, classroom_id, year, month_number);
call.enqueue(new Callback<ArrayList<ObjectivesReturn>>() {
@Override
public void onResponse(Call<ArrayList<ObjectivesReturn>> call, Response<ArrayList<ObjectivesReturn>> response) {
if (response.body().get(0).isValid()) {
try {
ArrayList<ObjApplications> objApplications = response.body().get(0).getObjectives();
ArrayList<Applications> applications = new ArrayList<>();
ArrayList<Applications> list;
for (int i = 0; i < objApplications.size(); i++) {
list = response.body().get(0).getObjectives().get(i).getApplications();
for (int j = 0; j < list.size(); j++) {
applications.add(list.get(j));
}
}
List<Event> eventList = new ArrayList<>();
for (int i = 0; i < applications.size(); i++) {
Date date = mSimpleDateFormat.parse(applications.get(i).getDate());
long timeInMillis = date.getTime();
Event event = new Event(Color.DKGRAY, timeInMillis, applications.get(i));
eventList.add(event);
}
mCalendarView.addEvents(eventList);
mCalendarView.shouldDrawIndicatorsBelowSelectedDays(true);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
@Override
public void onFailure(Call<ArrayList<ObjectivesReturn>> call, Throwable t) {
t.printStackTrace();
}
});
mCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
String dateString = mSimpleDateFormat.format(dateClicked);
List<Event> eventList = mCalendarView.getEvents(dateClicked);
Log.i(TAG, "onDayClick: " + dateString + " with events: " + eventList);
/*if (mCalendarView.getEvents(dateClicked).isEmpty()) {
Toast.makeText(getActivity(), "Esse dia não possue atividade cadastrada!", Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(getActivity(), PlanningMonthlyActivity.class)
.putExtra("date", dateString));
}*/
}
@Override
public void onMonthScroll(Date firstDayOfNewMonth) {
tvMonth.setText(mSimpleYearFormat.format(mCalendarView.getFirstDayOfCurrentMonth());
}
});
First of all, I get the events with Retrofit (I using an API) and after I get the events when I click on the day what I want
Hi did you manage to find the problem. I had a look through the code above and I could not see anything that would cause a problem. The only other thing I can say is that if you can upload an example project to github then I can clone the project and have a further look.
I will make a sample app and create a repo on my github.
Thank you, I should have suggested this from the start!
Its true. I'll start doing it now, I'll send you the link
I've copied the same code that I use in my application to demo app, and it works. I don't understand this! After that I tested it on my app and it didn't work. I don't know why it's like this.
Interesting. I would suggest start stripping bits of code and testing it to see what might be causing the problem. Maybe there's something in the layout causing some problem?
I'll change layout and try agian.
I created an activity and tested it and it worked. I created a fragment and tested it, it works until a certain date and then it doesn't click any more. I'm using the same code in both.
If you have a working sample that I can have a look at, that would be perfect then. It should work as expected in a fragment since thats what the sample app it self also uses.
I'll end the sample app to send you
Thanks for your help, if you upload to github I can check the project out.
You're welcome! I'll upload on my github.
Project: https://github.com/filipiandrader/demo-compact-calendar-view Works on activity and fragment, but in my real app doesn't work on fragment.
Nothing to solve my problem?
I did try the sample application but I couldn't reproduce any problems yet. Is there any specific steps that you followed to get the problem?
To get this problem, first I use Retrofit to get events to populate in CalendarView, I have problem after that, and I cant select some days.
But, I use your code in other activity and still get this problem.
So I have spent some more time debugging the demo app you uploaded and I'm still unable to replicate the problem. I tried with some emulators also.
Steps I followed: -Launch the demo app -Try selecting some day -Scroll some months both in future and past -Select more days
I was checking to see if some days are not selecting but I didn't see any problems. Can I suggest a few more things?
Have you tried with any other device/emulator? Does this problem happen without retrofit? Are you sure there are no errors happening when you call your api with retro fit? I see you are calling e.printStackTrace(); to print errors but I usually use the android Log class to log errors and messages.
I would suggest when you get a response from retro fit, add some dummy events without using the response from your api(comment your code out) and simply add something simple like so
Event ev1 = new Event(Color.GREEN, 1433701251000L, "Some extra data that I want to store.");
mCalendarView.addEvent(ev1);
Do you still get a problem?
One other thing you can try is fork the code and import the library into your project. Put the app in debug mode. Run your application and set a debug point in the onResponse method and step through. Without access to a project where I can reproduce the problem, it will be difficult for me to debug the problem otherwise.
I'll test again without Retrofit.
Hey and hows it going thanks so much for the awesome library but am stuck with an issue am using version 3.0.0 and when I click on a day on the Calendar the Callback for onDayClick is not being called, what could be the issue ??