Hallo sahabat CAN Creative, kembali lagi dengan android tutorial yang kekinian. Nah, kali ini kita akan membuat sebuah alat pilih untuk memilih jam dan menit. Di android sendiri, sudah menyediakan alat pilih dari pilih tanggal hingga pilih jam dan menit dengan dialog. Alat pilih ini menjadikan pengguna dapat memilih jam dan menit sesuai dengan ketentuan dan valid data. Langsung saja kita buat TimePickerDialog, pertama buat projek ataupun bisa menggunakan projek yang sudah pernah di buat. Selanjutnya buka main_activity.xml dan tambahkan kode seperti di bawah ini.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:textColor="#000"
android:textSize="16dp"
android:id="@+id/main_tv_jam"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pilih Jam"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/main_btn_pilih"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/main_tv_jam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pilih"
android:textAllCaps="false"/>
</RelativeLayout>
Di halaman ini, kita membuat satu TextView untuk menampilkan hasil dari waktu yang dipilih dan sebuah Button untuk memberikan aksi menampilkan TimePickerDialog. Selanjutnya kita membuka MainActivity.class dan inisialisasi Calendar dan buat method untuk menampilkan Dialognya, bisa lihat kode dibawah ini.
val myCalender = Calendar.getInstance()
fun pilihWaktu() {
val timeSetListener = TimePickerDialog.OnTimeSetListener { timePicker, hour, minute ->
myCalender.set(Calendar.HOUR_OF_DAY, hour)
myCalender.set(Calendar.MINUTE, minute)
val waktu = SimpleDateFormat(" HH:mm").format(myCalender.time)
val tvWaktu = findViewById<TextView>(R.id.main_tv_jam)
tvWaktu.text = waktu
}
TimePickerDialog(
this,
timeSetListener,
myCalender.get(Calendar.HOUR_OF_DAY),
myCalender.get(Calendar.MINUTE),
true
).show()
}
Method pilihWaktu(), kita membuat listener dari TimePickerDialog dan menampilkannya di TextView . Selanjutnya kita tambahkan kode di dalam onCreate() untuk menambahkan aksi untuk Button dan memanggil method pilihWaktu(). Bisa lihat kode dibawah ini.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btnPilih = findViewById<Button>(R.id.main_btn_pilih)
btnPilih.setOnClickListener {
pilihWaktu()
}
}
Kode lengkap MainActivity bisa dipraktikkan dibawah ini ya sahabat.
import android.app.TimePickerDialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import java.text.SimpleDateFormat
import java.util.*
class MainActivity : AppCompatActivity() {
val myCalender = Calendar.getInstance()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btnPilih = findViewById<Button>(R.id.main_btn_pilih)
btnPilih.setOnClickListener {
pilihWaktu()
}
}
fun pilihWaktu() {
val timeSetListener = TimePickerDialog.OnTimeSetListener { timePicker, hour, minute ->
myCalender.set(Calendar.HOUR_OF_DAY, hour)
myCalender.set(Calendar.MINUTE, minute)
val waktu = SimpleDateFormat(" HH:mm").format(myCalender.time)
val tvWaktu = findViewById<TextView>(R.id.main_tv_jam)
tvWaktu.text = waktu
}
TimePickerDialog(
this,
timeSetListener,
myCalender.get(Calendar.HOUR_OF_DAY),
myCalender.get(Calendar.MINUTE),
true
).show()
}
}
Setelah itu jalankan aplikasinya. Dan hasilnya akan seperti dibawah ini.

Selamat mencoba, semoga sefruit tutorial ini berguna untuk sahabat CAN Creative yang berminat menekuni bidang IT khususnya menjadi developer. Anda juga dapat mengetahui promo menarik seputar penawaran website, aplikasi, digital marketing ataupun SEO melalui website kami can.co.id. Kami juga aktif di media sosial instagram @cancreative, Line @cancreative.
Referensi : https://developer.android.com/reference/android/app/TimePickerDialog
Referensi : https://developer.android.com/guide/topics/ui/controls/pickers
Source Code di ada di Github : https://github.com/ramcona/timepikerdialogexample
Качественные WordPress ссылки в комментариях от 5000 уник. доменов заказать здесь .
Качественные WordPress ссылки в комментариях от 5000 уник. доменов заказать здесь .
I don’t need to tell you how important it is to optimize every step in your SEO pipeline. But unfortunately, it’s nearly impossible to cut out time or money when it comes to getting good content. At least that’s what I thought until I came across Article Forge… Built by a team of AI researchers from MIT, Carnegie Mellon, Harvard, Article Forge is an artificial intelligence (AI) powered content writer that uses deep learning models to write entire articles about any topic in less than 60 seconds. Their team trained AI models on millions of articles to teach Article Forge how to draw connections between topics so that each article it writes is relevant, interesting and useful. All their hard work means you just enter a few keywords and Article Forge will write a complete article from scratch making sure every thought flows naturally into the next, resulting in readable, high quality, and unique content. Put simply, this is a secret weapon for anyone who needs content. I get how impossible that sounds so you need to see how Article Forge writes a complete article in less than 60 seconds! order here.
Use artificial intelligence to cut turnaround time, extend your budget, and create more high-quality content that Google and readers will love. How It Works? WordAi is extremely fast and intuitive. Just enter your content, click rewrite, and in a matter of seconds, WordAi will rewrite an entire piece of content for you. WordAi comes up with different ways to express the same ideas by rewriting every sentence from scratch. This not only removes duplicate content, it also makes the rewritten content read completely naturally. Scale Your Business Make your entire content production process 10x more efficient. Use AI to create more high-quality, unique content that impresses clients and engages readers, all without having to put in more hours Register here and get a bonus.
Thanks again.
It is the best time to make a few plans for the future and it’s time to be happy.
ed doctors
sildenafil australia – viagra 100mg without prescription viagra sildenafil 25mg
pumps for ed best otc ed pills muse ed drug
tractor supply ivermectin pour on tractor supply ivermectin paste ivermectin rash
prednisolone sale – brand prednisolone cheap cialis sale
discount super active cialis cialis usa prescription cheapest cialis
ivermectin pills for dogs stromectol cheap edenbridge pharmaceuticals ivermectin
topical ivermectin for cats ivermectin cost australia ivermectin tablet
mixing viagra and cialis cialis or viagra buying generic cialis
buy clavulanate pill – where to buy cialis cheap cialis pill
best seller cialis cialis pills how long before cialis kicks in
gnc ed pills compare ed drugs pills for ed
ivermectin empty stomach how much is ivermectin for humans ivermectin pour on for sheep
sulfamethoxazole canada – brand sildenafil 50mg viagra 150mg pill
prescription drugs buy prescription drugs without doctor buy prescription drugs
buy finasteride online finasteride for hair loss propecia prescription
where to buy finasteride propecia 5 mg finasteride 5 mg prices
order cephalexin 500mg generic – cleocin 150mg usa erythromycin 250mg sale
ivermectin pill 1 ivermectin dosage for dogs herbal equivalent to ivermectin
п»їed drugs online from canada buy prescription drugs online without sildenafil without a doctor’s prescription
fildena without prescription – order fildena 100mg stromectol 12mg online
aarp approved canadian online pharmacies online pharmacies without prior prescription top rated canadian pharmacies online
best ed medications cheap erectile dysfunction the best ed pill
rhinocort oral – order antabuse 500mg online disulfiram for sale online
buy stromectol online stromectol without a doctor prescription buy stromectol online