Simple Alert Dialog Example for Android

Frequently used code samples and tutorials
Site Admin
Posts: 35
Joined: Tue Nov 18, 2014 2:39 pm

Simple Alert Dialog Example for Android

Postby vivekkalady » Thu Nov 27, 2014 6:01 pm

This is a simple example to show the usage of Alert.Dialog.This code is used to Show the About Us in an application

Code: Select all

private boolean aboutDialog() {
      // TODO Auto-generated method stub
      String vNo="";
      try {
         vNo=MainActivity.this.getPackageManager().getPackageInfo(MainActivity.this.getPackageName(), 0).versionName;
         vNo = "\n\nVersion : " + vNo;
      } catch (NameNotFoundException e) {
         // TODO Auto-generated catch block
      }catch (Exception e) {
      AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
      alertbox.setMessage("Developed by : Vivek.V\n\nEmail :"+vNo);
      alertbox.setNeutralButton("OK", new DialogInterface.OnClickListener() {

         // click listener on the alert box
         public void onClick(DialogInterface arg0, int arg1) {
            // the button was clicked


      // show it;

      return true;


MainActivity.this.getPackageManager().getPackageInfo(MainActivity.this.getPackageName(), 0).versionName;

will return the version no of the application.

Return to “Tutorials & Examples”

Who is online

Users browsing this forum: No registered users and 0 guests