Monday, June 18, 2012

How To Create Dialog Box In Android Application

The project describes how to draw a Dialog Box in your application.
Underlying Algorithm:
Basic description of algorithm in step by step form:
1.) Create a Project DialogExample
2.) Make sure to add following in your res/values/strings.xml file:
    <string name="hello">Hello World, DialogExample!</string>
    <string name="app_name">DialogExample</string>

    <string name="new_game_title">Difficulty</string>
    <array name="difficulty">
        <item name="easy_label">Easy</item>
        <item name="medium_label">Medium</item>
        <item name="hard_label">Hard</item>
3.) Run the application.
Steps to Create:
1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. DialogExample.
2.) Enter following information:
Project name: DialogExample
Build Target: Android 2.3.3
Application name: DialogExample
Package name: org.example. DialogExample
Create Activity: DialogExample
On Clicking Finish DialogExample code structure is generated with the necessary Android Packages being imported along with Following code must be added in DialogExample class to get the menu to work.
import android.content.DialogInterface;
import android.os.Bundle;
public class DialogExample extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
    private void openNewGameDialog()
                new AlertDialog.Builder(this)
                new DialogInterface.OnClickListener()
                public void onClick(DialogInterface dialoginterface,int i)
Output – The final output:

No comments:

Post a Comment