Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

AlertBox example in Android

Now we will see practical how we can design Alert dialog in Android.

Stepwise :

Step:1 First of all, we will create an application named 'alertdialog'. And now we will design its code.

Step:2 Now we will see its manifest file, which is the default generated and is named 'AndroidManifest.xml'.

Step:3 After that we will design its layout, for that we will open the file 'activity_main.xml' in the 'layout' folder, then inside it we have used relative layout, whose basic properties we already set, and then simply we have taken a text view, which has set basic properties such as height, width.

Step:4 After this we will see the 'strings.xml' file under the 'values' folder, here we have set some string which we will use inside our 'activity_main.xml'. Basic things we have specified in string.xml. 

Step:5 Now we have to design our main activity, for that we will see our MainActivity file inside 'java' folder, which is default generated, so now we have to design an alert dialog here.

Step:6 First of all, we will create Builder and we will give its instance 'builder', and firstly we will pass 'this' from it.

Step:7 Now with the help of the instance we have created, we will set the title.

Step:8 Now we will set the message, whatever message we want to set, we can set it here,                                 

builder.setMessage(""Do you want to close the app?"");

Step:9 Now we can add some more properties like this

.setCancelable (false)

.setPositiveButton (""Yes"",new DialogInterface().OnClickListener());

Step:10 This is done for the positive button but if the user wants to press no, then

.setNegativeButton (""No"")

Step:11 Now we will create an alert dialog,

AlertDialog alert-builder.creat ();

alert.show();

Step:12 So in this way, the code of our alert dialog has been designed, now let us execute it. When it is executed alert dialog is running correctly.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere