All Projects → codepath → android-view-helpers

codepath / android-view-helpers

Licence: other
Android View Helpers for Dialogs and more

Programming Languages

java
68154 projects - #9 most used programming language

Android View Helpers

This library is a collection of simple view helpers to make Android development easier. Right now, this library just has a few helpful classes but they will expand over time.

Installation

Download the latest jar file and drag the JAR to your "libs" folder.

SimpleAlertDialog

This is a simple way to bring up a modal alert dialog within a DialogFragment within a FragmentActivity. The dialog fragment used is the v4.support Fragment to support all Android versions.

Usage

In apps, you often may want to display an alert asking the user a question or displaying a message to the user. Creating an alert to display is easy:

class MyActivity extends FragmentActivity {
	public void showDialog() {
		SimpleAlertDialog.build(this, 
			"Sure you want to continue?", new SimpleAlertListener() {
				@Override
				public void onPositive() {
					// handle OK
				}
				
				@Override
				public void onNegative() {
					// handle cancel
				}
		}
	   ).show();
   }
}

By default, this will display the following alert:

AlertDialog

You can also adjust the alert to include no buttons, or change the button text. To display just an "Sure" button:

SimpleAlertDialog.build(this, 
	"Sure you want to continue?", "Sure", null, new SimpleAlertListener()
).show();

To display a "Yes" and "No" button:

SimpleAlertDialog.build(this, 
	"Sure you want to continue?", "Yes", "No", new SimpleAlertListener()
).show();

You can also customize the icon in the alert and other properties:

SimpleAlertDialog alert = SimpleAlertDialog.build(this, "Confirm?", new SimpleAlertListener());
alert.setAlertIcon(R.drawable.ic_some_icon);
alert.setAlertButtons("Yes", "No");
alert.show();

SimpleProgressDialog

Often in an application there might be a long running task that requires the UI to be blocked such as uploading an image. While this isn't the best UI, occassionally this can come up.

Creating an indeterminate modal progress dialog is easy:

SimpleProgressDialog dialog = SimpleProgressDialog.build(this);

By default, this will display the following alert:

ProgressDialog

You can dismiss the dialog once the task is complete with:

dialog.dismiss();

You can also adjust the progress dialog to have a custom message:

SimpleProgressDialog dialog = SimpleProgressDialog.build(this, "Uploading...");
dialog.show();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].