Home>

Book: "Foster basic and applied skills! Android application development textbook "
Unresolved reference: DialogButtonClickListener () in "5.3: Show Dialog"
I am in trouble because I cannot solve it.

Error message
app/build/generated/source/buildConfig/debug/com/example/kenta/listviewsample2/OrderConfirmDialogFragment.kt
Unresolved reference: DialogButtonClickListener
Unresolved reference: DialogButtonClickListener
Unresolved reference: DialogButtonClickListener
Modifier 'private' is not applicable to 'local class'
Modifier 'inner' is not applicable to 'local class'

Applicable source code

Language: Kotlin

package com.example.kenta.listviewsample2

import android.app.AlertDialog
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import android.widget.Toast
import androidx.fragment.app.DialogFragment

class OrderConfirmDialogFragment: DialogFragment () {
override fun onCreateDialog (savedInstanceState: Bundle?):
Dialog {
// Generate dialog builder.
val builder = AlertDialog.Builder (activity)
// Set the title of the dialog.
builder.setTitle (R.string.dialog_title)
// Set the message for the dialog.
builder.setMessage (R.string.dialog_msg)
// Set Positive Button.
builder.setPositiveButton (R.string.dialog_btn_ok,DialogButtonClickListener ())
// Set Negative Button.
builder.setPositiveButton (R.string.dialog_btn_ng,DialogButtonClickListener ())
// Set Neutral Button.
builder.setPositiveButton (R.string.dialog_btn_nu,DialogButtonClickListener ())
// Create a dialog object and return.
val dialog = builder.create ()
return dialog

// A member class that describes the processing when the action button of the dialog is tapped.
private inner class DialogButtonClickLitener: DialogInterface.OnClickListener {
override fun onClick (dialog: DialogInterface, which: Int) {
// Prepare a string variable for toast message.
var msg = ""
// Branch based on the tapped action.
when (which) {
// If it is a Positive Button ...
DialogInterface.BUTTON_POSITIVE->
// Store the order message.
msg = getString (R.string.dialog_ok_toast)
// If Negative Button ...
DialogInterface.BUTTON_NEUTRAL->
// Store the inquiry message.
msg = getString (R.string.dialog_nu_toast)
}
// Display of toast.
Toast.makeText (activity, msg, Toast.LENGTH_LONG) .show ()
}
}
}
}
`` `

What I tried

I tried to find a solution for multiple Unresolved references on the net, but I couldn't solve it.
I get stuck with this error every time.
I am sorry if I have asked elementary questions because I am a beginner.

Supplemental information (FW/tool version, etc.)

I am using Android Studio 3.6.3 for Mac.
If i have any other required information, please let me know and I will search and describe it.

  • Answer # 1

    It was solved by a spelling mistake and the position of {}.
    Thank you very much.