Тёмный

Using Date/Time Picker Dialog in Android Studio 

Tihomir Radev
Подписаться 15 тыс.
Просмотров 39 тыс.
50% 1

Video shows you how to use time and date picker dialogs in your Android app.

Опубликовано:

 

23 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 65   
@GeorgiDimitrovX
@GeorgiDimitrovX 5 лет назад
Благодаря за урока. Беше доста полезен.
@275phuongvy
@275phuongvy 5 лет назад
thank you. its great
@ardovich
@ardovich 7 лет назад
Nice tutorial!
@STARSxKING
@STARSxKING 5 лет назад
Thanks for help
@Nova-uo3fp
@Nova-uo3fp 5 лет назад
thank you my god
@unnickknotenganadie
@unnickknotenganadie 7 лет назад
Im getting an error on DatePickerDialog.show(); and TimePickerDialog.show(); Both .show are underlined in red. Compiler states that non static method show cannot be referenced from a static context Any clue?
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
DatePickerDialog.show(); should be datePickerDialog.show(); notice the lowercase letter at the start of the variable. same for the TimePickerDialog.show()
@unnickknotenganadie
@unnickknotenganadie 7 лет назад
I spent almost 2 hours trying to find the error, looked at stackoverflow, android developers site, google, etc.. and it was just a lowercase. Thank you so much! Is it possible to use this code to set a reminder? I'm building a notepad app, and I want to use this date/time picker to set reminders.
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
Yes! It can be used for this. You can use alarm manager to set your alarm for specific date and time :) Maybe I'll do tutorial for this in the future
@ujjwalrathod007
@ujjwalrathod007 7 лет назад
I get the error Cannot resolve the symbols i, i1 and i2. Do you have an idea how to fix it.. Did you declare it somewhere?
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
They are declared in the method itself onDateSet(). Look the code carefully you will see them.
@ujjwalrathod007
@ujjwalrathod007 7 лет назад
Thank you... It got resolved.. Still 1 more.. I get following .. Error:(64, 128) error: cannot find symbol method is24HourFormat(MainActivity).. Can you tell? I search on google but no any good point..
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
probably you didn't import the correct DateFormat. Remove the import and see the options.
@ujjwalrathod007
@ujjwalrathod007 7 лет назад
Thank you. It is done now and works on the Phone... In my case the date,time,month,year view is in the corner and not in the middle. if you can comment on that!!
@ujjwalrathod007
@ujjwalrathod007 7 лет назад
Thank you. It is done now and works on the Phone... In my case the date,time,month,year view is in the corner and not in the middle. if you can comment on that!!
@mohannadalsofyani9456
@mohannadalsofyani9456 8 лет назад
Could you please tell me how can I save the "tv_result" in my firebase database, and how to prevent two users to pick same date and time. "if one person picked date and time this will be unavailable for other (conflict another person will be served)". You did great code.. Many thanks
@TihomirRAdeff
@TihomirRAdeff 8 лет назад
+Mohannad Alsofyani This is more complex. It's hard to explain it in the comments. :)
@mohannadalsofyani9456
@mohannadalsofyani9456 8 лет назад
Appreciate your respond.. If you have any suggestions to do that, let me know please,, Thanks,,
@HungNguyen-oz1jc
@HungNguyen-oz1jc 5 лет назад
I followed exactly your video, but after click choose date and click ok, the timeDialog doesn't appear and the dateDialog just closes and didn't nothing, please help :(
@TihomirRAdeff
@TihomirRAdeff 5 лет назад
you missed something.
@HungNguyen-oz1jc
@HungNguyen-oz1jc 5 лет назад
@@TihomirRAdeff Do you have a source code, I just want to compare if I missed something Also, we don't need to add any dependencies right?
@Alii0007
@Alii0007 6 лет назад
Simple and to the point... thanks. If anyone wants to change colors user R.style.MyDialogTheme after context in the constructor.
@shahafnansulaiman3652
@shahafnansulaiman3652 5 лет назад
hello sir, how do i add two date picker and two time picker in same activity
@TihomirRAdeff
@TihomirRAdeff 5 лет назад
you should create a custom class that extends time picker and date picker and then in your main activity create two instances of this class. it's more advanced stuff but if you know java, nothing special.
@shahafnansulaiman3652
@shahafnansulaiman3652 5 лет назад
that the problem for me sir, because im new in this programing things, @@TihomirRAdeff
@TheWarrior95s
@TheWarrior95s 7 лет назад
I can't change default date(1900), i literally copy your code do you know why?
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
check your device/emulator date. I can't think of anything else
@johnbmw4684
@johnbmw4684 5 лет назад
when i click "DateFormat. " , i can't find "is24HourFormat" and if i write it it's an error ! what should i do , help !
@TihomirRAdeff
@TihomirRAdeff 5 лет назад
import "import android.text.format.DateFormat;" instead of "import android.icu.text.DateFormat;" or "import java.text.DateFormat;" more info: stackoverflow.com/questions/41507754/cannot-resolve-method-dateformat-is24hourformat-in-timepickerdialog learn to search google for errors!
@johnbmw4684
@johnbmw4684 5 лет назад
@@TihomirRAdeff thank you , it's working !
@tamimazmain2000
@tamimazmain2000 7 лет назад
Do you have the source code somewhere, like on github?
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
+jj Robot no, sorry. you have to rewrite it from the video.
@r-jayaraneta558
@r-jayaraneta558 7 лет назад
why my TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, MainActivity.this, hour, minute, DateFormat.is24HourFormat(this)); timePickerDialog.show(); the DateFormat.is24HourFormat did'nt correct by the Android studio its not show after i type DateFormat.
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
check your imports. you must have this at the top import android.text.format.DateFormat;
@r-jayaraneta558
@r-jayaraneta558 7 лет назад
thank you i'l try that! :D
@r-jayaraneta558
@r-jayaraneta558 7 лет назад
master i have a Error when i click Pick button its turn to Unfortunately stop :( whats wrong to my work can i have your source code :( please for my thesis right now. my thesis is a Mobile secretary that notif and alarm your schedule save it from sqlite database can you please help me.
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
what is your error in logcat?
@r-jayaraneta558
@r-jayaraneta558 7 лет назад
yes master. this is my whole CODES is there an error or inadequate. package com.example.knoxx.datetime; import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.icu.util.Calendar; import android.net.Uri; import android.os.Build; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.DatePicker; import android.widget.TextView; import android.widget.TimePicker; import android.text.format.DateFormat; import com.google.android.gms.appindexing.Action; import com.google.android.gms.appindexing.AppIndex; import com.google.android.gms.appindexing.Thing; import com.google.android.gms.common.api.GoogleApiClient; import java.text.DateFormatSymbols; public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { Button b_pick; TextView tv_result; int day, month, year, hour, minute; int dayFinal, monthFinal, yearFinal, hourFinal, minuteFinal; /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See g.co/AppIndexing/AndroidStudio for more information. */ private GoogleApiClient client; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b_pick = (Button) findViewById(R.id.b_pick); tv_result = (TextView) findViewById(R.id.tv_result); b_pick.setOnClickListener(new View.OnClickListener() { @RequiresApi(api = Build.VERSION_CODES.N) @Override public void onClick(View view) { Calendar c = Calendar.getInstance(); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); day = c.get(Calendar.DAY_OF_MONTH); DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, MainActivity.this, year, month, day); datePickerDialog.show(); } }); // ATTENTION: This was auto-generated to implement the App Indexing API. // See g.co/AppIndexing/AndroidStudio for more information. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); } @RequiresApi(api = Build.VERSION_CODES.N) @Override public void onDateSet(DatePicker datePicker, int i, int i1, int i2) { yearFinal = i; monthFinal = i1 + 1; dayFinal = i2; Calendar c = Calendar.getInstance(); hour = c.get(Calendar.HOUR_OF_DAY); minute = c.get(Calendar.MINUTE); TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this, MainActivity.this, hour, minute, android.text.format.DateFormat.is24HourFormat(this)); timePickerDialog.show(); } @Override public void onTimeSet(TimePicker timePicker, int i, int i1) { hourFinal = i; minuteFinal = i1; tv_result.setText("year: "+ yearFinal + " " + "month: "+ monthFinal + " " + "day: "+ day + " " + "hour: "+ hourFinal + " " + "minute: "+ minuteFinal + " " ); } }
@yaminiveerla4741
@yaminiveerla4741 6 лет назад
i got one error, can not resolve method date formate .is24HourFormat,
@sheery8086
@sheery8086 6 лет назад
import android.text.format.DateFormat;
@m.indrawijaya
@m.indrawijaya 6 лет назад
Sheery thank you
@1122looser
@1122looser 7 лет назад
I finished coding this but at the end i get the error: "Error:(13, 39) error: illegal character: '\ufeff'"
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
apparently you've mistaken any of the characters in the code. See at which line and copy the line here, so I can see where is your error.
@GabrielSestrem
@GabrielSestrem 7 лет назад
have you resolved it Sandi? I have the same problem...
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
copy the wrong line here so I can see which character is wrong :)
@GabrielSestrem
@GabrielSestrem 7 лет назад
Tihomir RAdeff Thanks for your support! I already fixed... Cheers!
@1122looser
@1122looser 7 лет назад
Sorry i was inactive on youtube for a while. The fix is to change all of the code to ISO 8859 and then back to UTF-8
@ef28525
@ef28525 8 лет назад
Why monthFinal = i1 + 1?
@TihomirRAdeff
@TihomirRAdeff 8 лет назад
because the months are from 0 to 11, that's why you should add +1
@myassistantprogram7870
@myassistantprogram7870 6 лет назад
how can i show am and pm please
@TihomirRAdeff
@TihomirRAdeff 6 лет назад
MyAssistant Program you have to change is24HourFormat
@muhammadateeq6795
@muhammadateeq6795 7 лет назад
it's helping sir but how to insert date and time in sqlite using same code and set alarm according to sqlite
@TihomirRAdeff
@TihomirRAdeff 7 лет назад
+ateeq shafique this tutorial is very far from your goal
@monttero
@monttero 6 лет назад
Si no les aparece el methodo DateFormat.is24HourFormat en TimePickerDIalog Importar import android.text.format.DateFormat; en vez de import android.icu.text.DateFormat; (ELIMINAR)
@ПавелИльинский-м9ж
Где листинг?!
@deniselhensley4724
@deniselhensley4724 7 лет назад
I'm
@deniselhensley4724
@deniselhensley4724 7 лет назад
9
Далее
Date Picker Dialog on Android
9:42
Просмотров 48 тыс.
Why Are Open Source Alternatives So Bad?
13:06
Просмотров 640 тыс.
Папины Дочки Наоборот!
24:57
Просмотров 533 тыс.
4 YEAR SIBLING DIFFERENCE! 😭 #shorts
00:11
Просмотров 11 млн
Develop simple Coundown Timer app in Android Studio
9:37
Date Picker & Time Picker | Android 🔥
14:41
Просмотров 23 тыс.
Can 1 Woke Teen Survive 20 Trump Supporters?
1:42:42
Microservices are Technical Debt
31:59
Просмотров 138 тыс.
Android Scheduled Task Example using AlarmManager
18:14
Create Popup Menu in Android Studio
6:13
Просмотров 45 тыс.
Trump vs Harris 2024 | Middle Ground
1:00:46
Просмотров 1,2 млн
Папины Дочки Наоборот!
24:57
Просмотров 533 тыс.