Simple Alert Dialog Example for Android

Frequently used code samples and tutorials
vivekkalady
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
         vNo="";
         e.printStackTrace();
      }catch (Exception e) {
         vNo="";
         e.printStackTrace();
      }
      
      AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
      alertbox.setTitle("About");
      alertbox.setMessage("Developed by : Vivek.V\n\nEmail : vivek@androidappmasters.com"+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
      alertbox.show();

      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 1 guest

cron