Posts Tagged ‘View’

Android: Creating a WebView dialog

Click here to read Android: Creating a WebView dialog

This Android post shows how to display a WebView inside a Dialog, that renders a website to the user. Since the WebView can load just about any web page, it’s possible to provide any information to users without launching the web browser, so they never have to leave the application.

For this tutorial, all code had been developed and tested in Android 2.1, both on an emulator and on a real device. As usual, an example application with the code featured in this tutorial is available for download at the end of the post.

The first thing required to place a WebView inside a dialog is to create a custom Dialog. After that, a WebView can be added to it. The easiest way to do that is to create a new Android layout file (in Eclipse, just right click the Project folder and select New -> Android XML file). Then, add the following code: (more…)

Android: how to create a loading screen – Part 3

Click here to read Android: how to create a loading screen – Part 3

This is the third and final post of a series that explains how to code a loading screen for Android. The other two previous posts (which can be found here and here), used two distinct approaches to solve the problem of executing code on a background thread and update the progress back to the application’s UI thread. However, both of them relied on an instance of the ProgressDialog class to display the current progress. In the following paragraphs, instead of using this type of dialog, a custom View inflated from a layout XML file is going to be created to achieve that purpose.

As the other two previous posts, all the code in this article has been created and tested in Android 2.1. An example Eclipse project is available at the end of the post.

(more…)

Android: how to create a loading screen – Part 2

Click here to read Android: how to create a loading screen – Part 2

This is the second tutorial from the post series that explains how to code a loading screen on Android. The first one can be found here. This post has a similar approach to the previous one, except this time, instead of using a AsyncTask to execute code on the background thread, a Thread and Handler objects are going to be used to achieve the same results.

The Activity featured below is somewhat similar to the first post, except this time, the UI rendering related functions calls will be more scattered throughout the Activity’s body. Additionally, the Runnable interface is going to be implemented multiple times in the below code. Not only that, but now it’s necessary to “kill” the thread manually after the code executes, a task that is handled automatically by the AsyncTask class (see this thread for more info).

All code has been developed and tested in Android 2.1, and is available for download at the end of the post.

(more…)

Android: how to create a loading screen – Part 1

Click here to read Android: how to create a loading screen – Part 1

This is the first of three Android post in a series that explains how to code a simple loading screen that shows the progress of operation before the application’s View is loaded. This first tutorial objective is to create this loading screen in simplest way possible. The code featured in this tutorial has been developed and tested in Android 2.1, but it should work without much modification in later versions. All code featured in this tutorial is available for download at the end of the post.

Because of the nature of the Android operational system and the Activity stack, there’s no way to precisely determine the loading progress of an Activity. That’s why, in the below example, the Activity is going to be started, but instead of loading the standard View, it will load a ProgressDialog object and simulate a computationally heavy process on a background thread right on the beginning of the onCreate() method.

(more…)

Android: Initialize View child class object from a XML file

Click here to read Android: Initialize View child class object from a XML file

This tutorial shows how to inherit from the View class to create your own customized View element, and how to initialize an object from this child class with parameters defined at a layout XML file. There are two major advantages in this approach over initializing the extended View object at the Activity.

The first is that the Java part of your code remains clean, without a lot of member variable assignments to set the View’s basic parameters. The second and most important, is the possibility to instantly preview the changes at the Graphical Layout tool in Eclipse without the need to execute the application. This means that the space this customized View element takes on the screen can be immediately be seen and adjusted, if necessary.

(more…)