Alert dialog box include custom dialog and Chat Dialog Fragment

 Welcome to "Android Super Nerds". Thanks for coming back to my site, I really appreciate that and if you guys are new to my Site please do check my previous articles as well.

Nowadays, any application we consider .i.e. web or mobile, notifying our user about warning, information, new notification message, error, or any status related to any crucial action message via an Alert Box or more alike a DialogBox is a best practice. 

Alert Dialog Box

An alert dialog box is a medium to display and prompt an important message to our user. Even the action button can be seen on it, which seeks the user to make his decision. 
A dialog box can be a simple approach for message sharing to our user but it too can vary depending on its already defined classes and method. 
Its class already have defined methods and attribute field given below๐Ÿ —

1. Title
2. Icon
3. Message field
4. Action buttons
5. Custom style theme 
6. Input field
7. Dialog cancelable (optional)      

Most of the Apps have different requirements for dialog box appearance and action button handler. So the custom feature is only the solution. Custom Dialog Box can be implemented on the existing Activity, fragment, or some generic calls like๐Ÿ —

Inside a method of the class

Yes & No button dialog - Let's start with something simple, like yes & no option alert dialog. And for doing that we need to create an instance of DialogInterface.OnClickListener class. This instance handles the click event for  both positive and negative button. Something like this๐Ÿ —

Ok & Cancel button dialog - Same approach can be used for ok & cancel option alert dialog but not required any instance of DailogInterface. Code will be something like this๐Ÿ —

Ok button dialog - Same as previous code approach but not required a negative button. And Code will be something like this๐Ÿ —

Custom Layout Dialog - For inflating the layout on the dialog view, first it is required to create a layout that needed to be displayed on the dialog view once it is prompted. And for doing that we need to use LayoutInflater instance, which also require the view id identification for initializing the view and its click event. Code can be seen this๐Ÿ —

Layout Design


Custom dialog box implementation via Dialog Fragment

For handling the most complex dialog design and event handling, it is always a better choice to use the Dialog Fragment. And for doing so first create a class and then extend it with Dialog Fragment which is turn gives you the access to add custom layout and other events. 

The code for displaying this dialog, differs from other code which we show earlier.๐Ÿ —

Entire Dialog Fragment Code can be like this๐Ÿ —

If you guys are still on my page, then thanks for staying on it and I really appreciate that. 


Happy Coding...๐Ÿ˜ƒ