I'm trying to manipulate views inside a dialog, but the only way I can retrieve the views is in the Java old fashioned way, like this:
class MyDialog: DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val alert = AlertDialog.Builder(context!!)
val inflater = LayoutInflater.from(activity)
val view = inflater?.inflate(R.layout.pg_dialog, null)
with(alert) {
setView(view)
setNeutralButton(R.string.scambio_back, DialogInterface.OnClickListener({ _: DialogInterface, _: Int -> dialog.dismiss() }))
}
view?.findViewById<TextView>(R.id.dialog_name)?.text = person.name
view?.findViewById<TextView>(R.id.dialog_surname)?.text = person.surname
return alert.create()
}
}
Do you know any way to retrieve inner views in Kotlin, avoiding findViewById?
[Edit] Here's the build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.project.persons"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
// Firebase
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.firebaseui:firebase-ui-auth:3.2.2'
implementation 'com.facebook.android:facebook-android-sdk:4.30.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
apply plugin: 'com.google.gms.google-services'