Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 18.104.22.168 release ready!
In this blog, we going to discuss the Kotlin Extension Function.
When we want to add any extra function to the class with the existing functionality then the inheritance comes to mind. We inherit that existing class and add the new functionality in the child class.
Kotlin supports the extension function which will allow extending the existing class functionality without inheritance. We simply add the new method to the existing class just with the help of the class name and can access that method easily.
We can create the extension function in kotlin like a normal function only we have added the class name just before the function name Activity.showCustomAlert()
Inside our extension function, we have displayed the alert dialog with the details that we have received on the extension function parameters.
Here the context is basically the activity context. In my case, I am using BaseActivity as the activity name so you can add your own activity.
Then the next, we have the title and content or message of the alert. Cancelable param is used for setting the alert as cancelable or noncancelable if you ignore to pass the value at the function call time it will set the default value as true.
Next, we are passing the positive and negative button text and the click listener functionality. It will also be used as null by default if we did not pass any.
We have added this new extension function inside the activity class now we can access the method anywhere in our class.
In this blog, we have learned about the implementation of the Kotlin Extension Function.
For more information regarding the Kotlin Extension Function follow the link.
Thanks for reading this blog. You can also check other blogs from here.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
All communication is done through a ticket system. I appreciate the regular almost daily updates of what is being worked on, and communicating changes or updates is easy through this system. Mobikul's response timeframe is quick.
Owner, Shop ATV Escape
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.