Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

Java can i override with additional parameter ?

views
     
TSnarf03
post Nov 20 2018, 12:59 AM, updated 6y ago

Look at all my stars!!
*******
Senior Member
4,544 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


its going to be kotlin, there isnt a kotlin tag so im going to assume they are equivalent

and im not using the code tag for the majority of the code cause some info will be missing

refer to the code below,

i able to call the window using

CODE
MessageBox().show(supportFragmentManager, "")


now my question is, how do i pass in additional parameters(ie title and description text that shows up on the messagebox) from the above code into the "MessageBox : DialogFragment()" ? i dont want to hardcode the Messagebox class, i assume ill be having plenty of them, and those buttons on the messagebox will not do anything beside just closing the messagebox. and if possible, 1 line of code only.

user posted image
TSnarf03
post Nov 20 2018, 07:35 AM

Look at all my stars!!
*******
Senior Member
4,544 posts

Joined: Dec 2004
From: Metro Prima, Kuala Lumpur, Malaysia, Earth, Sol


nvm, i solve it by not overriding =P


CODE

class MessageBox : DialogFragment(){
   var strMessage = ""
   var strTitle = ""
   override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
       return activity?.let {
           this.isCancelable = false
           val builder = AlertDialog.Builder(it)
           builder.setTitle(strTitle)
           builder.setMessage(strMessage)
           builder.setPositiveButton("OK") { dialog, id ->
               }
           builder.setNegativeButton("Cancel") { dialog, id ->
               }
           builder.create()
       } ?: throw IllegalStateException("Activity cannot be null")
   }

   fun show(fm: FragmentManager, strTitle : String, strMessage : String) {
       this.strTitle = strTitle
       this.strMessage = strMessage
       this.show(fm, "")

   }
}


 

Change to:
| Lo-Fi Version
0.0123sec    0.44    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 07:16 AM