dialog box on android

Download Dialog Box ON aNDROID

Post on 31-Jul-2015

23 views

Category:

Documents

2 download

Embed Size (px)

DESCRIPTION

Android Programming

TRANSCRIPT

Where is it?

ATTENTION ATTENTION gear.huuah.com has launched. Visit the shop at http://gear.huuah.com/. Lots of Photo Gear at the moment ATTENTION ATTENTION Itsplanned.com is just launched! - Task and project management made easy. Try it for free.Create your own lists of things to do - arrange the order to do them - move them around - group them No limitations - all free project management - try the free demo before signing up - demo: itsplanned.com

Dialog boxes in AndroidDialog boxesShowing dialog boxes from an android application can be usefull.

02.04.2010

Follow me on Twitter

ContentsDialog boxes Info boxes Alert boxes Yes/no boxes

This article will be using a layout like this 4 buttons with their own function (complete code id listed last in this article):

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Yes/no boxes Loading box Complete code main.xml dialogboxes.java

Related stuffAndroid Progress Bar and Thread updating Using TableLayout on Android

Info boxesAn info box is called a Toast on the Android OS. A toast message is a small window that appear in the button half on the device screen. It should only be used as an information service to the user. The window disappears by itself, so as a developer you can not be sure that the user actually sees the message displayed. If you want to user to take action on the popup window, you should use an alert dialog instead this is covered later on.

Android writing and reading files How to make tabs bookmarkable with jQuery The basics of Android intents and activities

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

The Toast message is very easy to create. The most simple way to display a toast is by calling the maketext()-method like this: ... Toast.makeText(this, "This is the Toast message", Toast.LENGTH_LONG).show(); ... This will display a box like this:

Further readingJQuery

Alert boxesopen in browser PRO versionAre you a developer? Try out the HTML to PDF API

TYPO3 Android

pdfcrowd.com

The Alert box should be use when you want to make sure, that the user reads and takes action on the information window. To display the alert window, can be done like this: ... // prepare the alert box AlertDialog.Builder alertbox = new AlertDialog.Builder(this); // set the message to display alertbox.setMessage("This is the alertbox!"); // add a neutral button to the alert box and assign a click listener alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {

Android

TopicsAndroid Development

// click listener on the alert box Howto public void onClick(DialogInterface arg0, int arg1) { // the button was clicked Itsplanned.Com Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show(); } Java }); // show it alertbox.show(); JQuery Misc TemplaVoila

...

This will popup a window like this:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

TYPO3 Wordpress

When is OK button is clicked, it will in this example show a toast message like this:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Yes/no boxesIf one button on the alert dialog isnt enough we can use the setPositiveButton() and setNegativeButton() on the AlertDialog Builder like this: ... // prepare the alert box AlertDialog.Builder alertbox = new AlertDialog.Builder(this); // set the message to display alertbox.setMessage("This is the alertbox!");

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

alertbox.setMessage("This is the alertbox!"); // set a positive/yes button and create a listener alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface arg0, int arg1) { Toast.makeText(getApplicationContext(), "'Yes' button clicked", Toast.LENGTH_SHORT).show(); }

});

// set a negative/no button and create a listener alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() { // do something when the button is clicked public void onClick(DialogInterface arg0, int arg1) { Toast.makeText(getApplicationContext(), "'No' button clicked", Toast.LENGTH_SHORT).show(); }

});

...

// display box alertbox.show();

This will show a window like this:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

When either of the buttons is clicked it will run the assigned listener. Here we have clicked the yes button:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Loading boxIf you want to display a loading window or some kind of progress alert it can be done with the ProgressDialog like this: ... // prepare the dialog box ProgressDialog dialog = new ProgressDialog(this); // make the progress bar cancelable dialog.setCancelable(true);

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

dialog.setCancelable(true); // set a message text dialog.setMessage("Loading..."); // show it dialog.show();

...

This will popup a progress window like this:

This window will not close by itself. You have to make it complete, by running a code that increment the internal counter on the ProgressDialog, so that the progressdialog can calculate the percentage by itself. For this we should use a thread-based application, that runs some code in the background and from there set the progress bar at the given value. This is not covered in this article though.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Complete codeThe small code samples above are shown here in the complete formation, including the main.xml layout.

main.xml

Recommended

View more >