Skip to main content

Posts

Showing posts with the label Picker

android kotlin - DatePicker example

MainActivity.kt package com.cfsuman.kotlintutorials import android.os.Bundle import android.widget.* import androidx.appcompat.app.AppCompatActivity import java.text.DateFormat import java.util.* import kotlin.random.Random class MainActivity : AppCompatActivity() { private lateinit var calendar:Calendar override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Get the widgets reference from XML layout val textView = findViewById<TextView>(R.id.textView) val datePicker = findViewById<DatePicker>(R.id.datePicker) val buttonGet = findViewById<Button>(R.id.buttonGet) val buttonSet = findViewById<Button>(R.id.buttonSet) // Initialize a new calendar instance calendar = Calendar.getInstance() // Get the Calendar current year, month and day of month val thisYear = calendar.get(Calendar.YEAR) ...

android kotlin - TimePicker example

MainActivity.kt package com.cfsuman.kotlintutorials import android.os.Bundle import android.widget.* import androidx.appcompat.app.AppCompatActivity import kotlin.random.Random class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Get the widgets reference from XML layout val textView = findViewById<TextView>(R.id.textView) val timePicker = findViewById<TimePicker>(R.id.timePicker) val buttonGet = findViewById<Button>(R.id.buttonGet) val buttonSet = findViewById<Button>(R.id.buttonSet) val buttonToggle = findViewById<Button>(R.id.buttonToggle) // Set a time change listener for time picker widget timePicker.setOnTimeChangedListener{ view,hourOfDay,minute-> textView.text = "Time Changed ${getHourAMPM(hourOfDay)} " ...