Android Studio - Open DatePickerDialog from an AppCompatDialog

101
May 06, 2022, at 7:40 PM

i want to open a DatePickerDialog from an AppCompatDialog.

private fun pickDate() {
    etProduktDatum.setOnClickListener {
        getDateTimeCalendar()
        DatePickerDialog(this,this,year,month,day).show()
    }
}

When i try to create it, android studio complains that there is a Type mismatch on the first parameter of DatePickerDialog:

Type mismatch. Required: Contex Found: EinkaufslisteProduktgekauftDialog

This is my Dialog:

class EinkaufslisteProduktGekauftDialog (context: Context, var produkt : Produkt?, var addDialogListener: AddDialogListener) : AppCompatDialog(context), DatePickerDialog.OnDateSetListener{


var day = 0
var month = 0
var year = 0
var savedday = 0
var savedmonth = 0
var savedyear = 0
Answer 1

You can take the context of the activity where ever you are in. You don't want the context of your dialog. Or you call this.getContext (I don't know the kotlin way there).

DatePickerDialog(this.context,this,year,month,day).show()

Rent Charter Buses Company
READ ALSO
Android Studio BumbleeBee Freeze when gradle is building

Android Studio BumbleeBee Freeze when gradle is building

since i updated to bumblebee android studio suddenly freezes when i want to build/run the appit freezes while gradle is building the project

115
Warning after upgrading Android Gradle Plugin to 7.1.1

Warning after upgrading Android Gradle Plugin to 7.1.1

After upgrading Android Gradle Plugin from 70

121
Flutter run error. exiting with code 1 Could not resolve all artifacts for configuration ':classpath'

Flutter run error. exiting with code 1 Could not resolve all artifacts for configuration ':classpath'

I am trying to run my first flutter app in visual studio code, but when I run flutter run -v, execution end it with errorSee it below:

76
Remove a variable of a class from another part of the code

Remove a variable of a class from another part of the code

I have a class that I pass as a parameter to a functionThis class contains various companion objects

124