Adding Events to CompactCalendar CalendarView in android studio (java) from api call - java

Please I wanted to add events (highlight dates) to a calendar view. I used the default calendar view in android studio but I was not able to achieve it using that so I tried using a different library which was CompactCalendar (https://github.com/SundeepK/CompactCalendarView) everything works well but when I try to add events using the data from an API call it does not work because I cannot update the calendarView with the data. Before you add an Event on the CalendarView,
1. You must first create an instance of an Event (the Event class comes with the library), Here is where you specify the date to highlight
2. You must finally call the addEvent method on the calendarView instance created earlier.
for example, the code below demonstrates how adding events in the library works
Event event = new Event(color, date, data);
calendarView.addEvent(event)
This works when I manually create an event using hardcoded dates and call the addEvent method on the calendar. But when I make an API request to my endpoint to fetch the data, I cannot update the calendarView with the data gotten from the onResponse callback from (Google's volley library). Please note that doing some debuggging showed that my data is gotten and no error occurred from the API call, but the calendarView does not update when I call the addEvent method after it has been created.
Thank You.

Related

How to get in Liferay calendar SyncEntryId of a single google recurring event?

I created a Calendar connector for google. My new functionality is delete a single occurrence of recurring events but it doesn't work. I'm not able to get the SyncEntryId of a single event.
syncEntry = SyncEntryLocalServiceUtil.fetchSyncEntry(
getSyncGroupId(), mappedId);
This code create the id but when are reccurring events the pattern of id is like "XXXXX_20190522" and, in this case, sync entry is null. When it isn't a recurring events the id is like "XXXXX".
Have you seen the Google's Api ??

What's the name of the concept I need to learn to solve this: field used before Firebase data updates it

So I have a list that is updated from firebase.
In my mainactivity's onCreate, I set the listener for changes. However, the next line of code uses the list immediately. This line runs before my list is updated, thus causing an error.
What is the name of the concept i need to grasp in order to solve this problem?
Firebase Realtime Database callbacks are asynchronous. You'll need to learn asynchronous programming to deal with most of the Firebase SDKs. It means that method calls return immediately and expect to receive results some time later in a callback that was passed as an argument to the method. See the documentation for more information.

Android: Update TextView from Non-Activity Class

I am writing an Android App and i need to display some results from a non-activity class.
Basically my App gets the current location, activity and other things, and on those i run some functions, for example to check if the user has been at that place before.
Anyway, an intent triggers these functions, and at the end of the function I want to update a TextView with the result of these functions.
But it doesn't seem to work from anywhere besides MainActivity. I tried making the TextView static, but that doesn't seem to work, and returning the results to MainActivity is not possible either in since it is not called directly from MainActivity.
Does some have an idea on how to solve this problem?
This is my first android project, so there's still a lot of thing i don't know about. Thank you!
I don't know exactly what your code looks like, but do you have a model class that holds all your data (for example, some kind of singleton)? If so, you could just save the updated text there, and then update the TextView in a callback method.
If that doesn't fit what you're doing, I would considering refactoring your code so that the text you want is sent back to your MainActivity. You mentioned that the method is not called directly, but could your calculations pass the text to an intermediate class, which passes it to your MainActivity?
You should not update the ui drom background thread.
If you want to update the ui from background thread use Handlers,AsyncTask or use some other thread concepts.
If you want to update the UI fro Service or Broadcast receiver for eg you receive a message inside onReceive of broadcasrReceiver now to update the ui use sendBroadcast and inside your activity registet a dynamic Broadcast receiver and then update

Can i use Cursor loader instead the asynctask?

I'm studying and learning about Android Java world.
I'm building my first Android App, using Json to get all data from the application, and Java to display it. I created an activity with a Chat between two users, and I am using Asynctask to get and insert the Data.
But today I had an issue, because I have to update the listview everytime that a user inserts a new message, and Asynctask doesn't do that. I searched more about that, and some user said to me that I should use Cursor Loader instead the asynctask.
My questions are, whats the difference between both?
Do Cursor Loader reload my Listview automatically everytime that new Data is inserted into my Database?
Am i able to get the Json Data using Cursor Loader?
Thank you.
Unfortunately, telling you how a CursorLoader works in a simple answer would be confuse because it envolves a lot of code if you preetend to use Content Providers, but there is plenty of Google material explaining how it works!
As stated in Android Developers - CursorLoader Tutorial page:
A CursorLoader runs an asynchronous query in the background against a ContentProvider, and returns the results to the Activity or FragmentActivity from which it was called. This allows the Activity or FragmentActivity to continue to interact with the user while the query is ongoing.
Also, in the second part of that tutorial there is a section that answers your second question:
To display Cursor data returned by CursorLoader, use a View class that implements AdapterView and provide the view with an adapter that implements CursorAdapter. The system then automatically moves data from the Cursor to the view.
And for the third question: you can do anything with Java! :)
There is also a good tutorial on this available at Voggela: Android SQLite database and content provider.

How to update the alarm ringing time While updating calendar events?

I'm trying to set alarm for calendar events that are inserted through my application. I have also set alarm for events(i.e) when calendar event notification shows, Alarm also sounded. Now, if I update the event time, I must get the alarm time also be updated from old time to new time. How to make out this?
Any help is highly appreciated and Thanks in advance...
Does android have any 'foreign key' type relationship between Events and their Reminders in its calendar content provider? I think there it is, and can help you. The link below is from android calendar app's source, and it is related to edit event activity, used in editing and inserting events. in save() method, used in this class, you can find how android itself saves events, and stores them, I think it would help.
click to see android calendar src code

Categories