Monday, December 5, 2011

AlertBox in Android (Basic)

This is the simple and very basic Tutorial for Android Alert Box Dialog.
Just create alert box and you can call it whenever you want in app

so let's try this small app

 -------------------------------------------
App Name: AlertBoxBasic
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 / API 10
Default Activity Name: AlertBoxActivity
-------------------------------------------

 AlertBoxActivity.java

package com.rdc;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class AlertBoxActivity extends Activity {   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //call alert box code to display dialog
        alertbox("Alert Box","Your Application has been started..");
    }
   
    //create alert dialog box
    protected void alertbox(String title, String mymessage) 
    { 
    new AlertDialog.Builder(this) 
       .setMessage(mymessage) 
      .setTitle(title) 
       .setCancelable(true) 
       .setNeutralButton("OK", 
          new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int whichButton){} 
          }) 
       .show(); 
    }
}

main.xml



AndroidManifest.xml





 
 
 
 





The output Screen will be like this..

You can download the complete source code zip file here : AlertBoxBasic

cheers!!

 I'd love to hear your thoughts!

No comments:

Post a Comment