I need a Date picker to be able to set it's time types(Gregorian,Jalali or Hijiri)from setting and change it to each others too... and all the items that work by DATE will get new value...as I didn't have found any library to do this i tried to ask best Coders to help me by their libraries...if your answer is yes then how is possible to change all the dates by changing the type of calendar?
some one said "use joda time Library" but there is no tutorial.is joda time Ok?
پی نوشت : please comment up if you have same BROBLEM...to ANSWER]أۀ(in fa) sooner
Related
I am using CalenderView in android. I have a list of predefined dates as ["2019-02-15","2019-02-16","2019-02-17"]. When Calender is initialized and shown on Activity/fragment i want this dates to be selected.How to achieve this.
I am initializing calender this way
calender=v.findViewById(R.id.cal);
calender.setMinDate(System.currentTimeMillis()-1000);
How to achieve this ?
Looking into the Android API Reference you find this function:
CalendarView.setDate(long date)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone. https://developer.android.com/reference/android/widget/CalendarView.html#setDate(long)
So in your case you should call:
calender.setDate(long date);
In order to get the milliseconds, you should first parse your date string and then convert them to milliseconds.
Additionally I am not sure and I dont't think that it is possible to select more than one date at a time.
You cannot disable specific dates in the default CalendarView of android, for that you've to fork that widget and do your customisation. Then the other option is to use third party libraries like
material-calendarview
Using this library you can easily disable custom dates and apply custom background color and so on.
Material-Calendar-View
This is also other third party option which provides multiple date selection and so on.
Community,
Basically I'm working on my own Calendar App. Its a private Project to add specific functions and I wont use for example s-planner, Calendar and so on.
The Google Calendar is a great choice in my opinion but I want to learn the basics by myself.
I just started a few days ago and here we go:
The App needs 4.4 Kitkat and above versions. I started with a basic calendar view, looking like this:
So it should be possible to add Events and Reminders. It is possible to check which date is selected and working with a Date Tim Picker dialog? Or should I create an GridView and fill it. Maybe that way:
Just use the calendar api and create an Instance like this:
Calendar calendar = GregorianCalendar.getInstance();
But there is for example, no function which gives me the Dates of a Month in a Array . How its possible to fill it.
I just looked for some examples :
https://www.toptal.com/android/android-customization-how-to-build-a-ui-component-that-does-what-you-want
Is this necessary? Maybe there is an easy way. I don't understand the Calendar Api.
The Logic behind the calendar could be organized with the CalendarContract.
For example:
Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(calIntent);
So that's not the case now.
I just want to know how I can create the calendar structure and display it. Maybe a hint which way is possible to display dates of another Month ( for example: the first November 2016 = Tuesday so i should display the 31.10 too)
I guess there are a lot of information that I miss at this time. Hope some of you can help me. I'm sorry for my English, it isn't the best but you should understand the point. Have a great Day.
Its also my first post here, so let me know which information is missing or what I should reformat.
Are you looking for something like this. This is a fully customised calendar where you can add events to dates , can listen to date change etc :
https://github.com/khetanrajesh/CustomCalendar
I'm really stuck with a certain problem and I'm hoping someone can help me understand the problem and come to a solution. I've looked online a fair bit but can't see an answer unless it's been staring me in the face :-/
Basically, I'm creating a very basic TV Guide app. It parses data from an RSS feed which has days offset (yesterday was -1. today is 0, tomorrow is 1, etc etc) and I'm trying to implement a DatePicker that allows the user to see what is on a particular channel when they select yesterday, today, tomorrow, etc.. but if they pick a date that is out-with the range (at the moment it's a week in advance), a simple Toast message will be displayed.
My questions I guess are, firstly, how do I use maybe an IF ELSE to either parse the specific channel data for the day the user wants or display an error Toast message, and, how do I go about converting the days from what the user has put in compared to the actual date today into integers? If they select yesterday's date it will go to URL "http://example.com/-1/channel", if they select tomorrow's date it will go to URL "http://example.com/1/channel" etc etc etc.
Code is available if anyone needs to see it, but I think if someone would be kind enough to explain the logic, I'd like to see if I can come to the answer myself...
Thanks a lot folks!!
You should use a DatePicker to allow the user to choose the when.
Time in Android is stored on a long (not an int). And the long time can easily be converted back and forth between long (always milli-seconds) and a Date object.
The Date object gives you all sorts of tools to compare before and after, look at months, minutes, hours, etc.
The current time is determined by:
long nowMs = System.currentTimeMillis();
int nowSec = (int)(nowMs / 1000);
There is also a very important Calendar object. This allows you to parse textual date formats as delivered by your http functions in and out of various dates.
For example:
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss Z");
String text = sdf.format(cal.getTime();
You will have to put all these tools together with a DatePicker example such as the one here Create a DatePicker to complete your TV Guide application.
Reference:
Date
Calendar
DatePicker
EDIT : Check David's Answer its better.
First Filter the date selected with today's date. You can compare it by date.isbefore(date) or date.isafter(date) these booleans will let you tell know if a date is of past or future or present. then to further calculate the days inbetween you can make a method with switch statement that will basically convert the selected date and the current date into miliseconds(Date.getTimeinmiliseconds)
if the date is of past take the difference of present time in miliseconds and past date in miliseconds. If the date is of future do the opposite. Take the difference and convert it to days difference with appropriate sign(negative/positive).
Please refer this link for a better coding example
I'm trying to program an android app that show's the current week_of_the_year but haven't found anything similar to what I want, I've seen the date picker but that doesn't show the week numbers and I've also been on android developer site.
So is there any way to view the current week_of_the_year in a really simple way?
If there's anyone who can show me this I'll be greatly appreciated.
new GregorianCalendar().get(Calendar.WEEK_OF_YEAR);
This should give you the current week in the current time zone. If you need it for a specific date, there are alternate constructors for GregorianCalendar.
The easiest way to do this on Android is probably to use the Time class:
int currentWeek = new Time().getWeekNumber();
Hey,
I want to update the date to a year before 1970.
the updateDate function wants a date since 1970.
the widget itself allow you to select 1900-2100 (from what i read you can change it also using an xml to describe the control)
any solutions?
if not, what widget do you use to select date (e.g. birth date...)
Thanks.
Just use a negative number when you pass in the years.