Android TableLayout example

In Android, TableLayout let you arranges components in rows and columns, just like the standard table layout in HTML, <tr> and <td>. In this tutorial, we show you how to use TableLayout to arrange button, textview and edittext in rows and columns format, and also demonstrates the use of “android:layout_span” to span view in 2 …

Read more

Android RelativeLayout example

In Android, RelativeLayout let you position your component base on the nearby (relative or sibling) component’s position. It’s the most flexible layout, that allow you to position your component to display in anywhere you want (if you know how to “relative” it). In RelativeLayout, you can use “above, below, left and right” to arrange the …

Read more

Android wrap_content and fill_parent example

In Android, you always put either “wrap_content” or “fill_parent” on component’s attribute “layout_width” and “layout_height“, did you wonder what’s the different? See following definition : wrap_content – The component just want to display big enough to enclose its content only. fill_parent – The component want to display as big as its parent, and fill in …

Read more

Android LinearLayout example

In Android, LinearLayout is a common layout that arranges “component” in vertical or horizontal order, via orientation attribute. In additional, the highest “weight” component will fill up the remaining space in LinearLayout. In this tutorial, we show you how to use LinearLayout to display 3 buttons in vertical and horizontal order, and also how “weight” …

Read more

How to open an URL in Android’s web browser

Here’s a code snippet to show you how to use “android.content.Intent” to open an specify URL in Android’s web browser. button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://mkyong.com")); startActivity(intent); } }); Note For full example, please refer to this – Android button example. References Android Button JavaDoc Android …

Read more

Android button example

In Android, just use “android.widget.Button” class to display a normal button. In this tutorial, we show you how to display a normal button, add a click listener, when user click on the button, open an URL in your Android’s internet browser. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. Note …

Read more

Android ImageButton selector example

In last Android tutorial, you use “ImageButton” to display a “Button” with a customized background image easily. However, you can do more than that just a simple image, Android allow you to change the button’s image depends on different states like button is focused or button is pressed. This example is referenced from this Android …

Read more

Android ImageButton example

In Android, you can use “android.widget.ImageButton” to display a normal “Button“, with a customized background image. In this tutorial, we show you how to display a button with a background image named “android_button.png“, when user click on it, display a short message. As simple as that. Note You may also like this Android ImageButton selector …

Read more

Maven 3 need to know the plugin version

In Maven 2, if you didn’t specify the version for each plugins that used in pom.xml, it will pick the latest plugin version automatically, which is very convenient. However, in Maven 3, if you didn’t explicitly specify the plugin version, it will prompt you warning message. Read this “Maven 3 compatibility” for detail. For example, …

Read more

Android ImageView example

In Android, you can use “android.widget.ImageView” class to display an image file. Image file is easy to use but hard to master, because of the various screen and dpi in Android devices. Note Please refer to this official Android’s “Drawable Resource” and “Screen Support” article for better understand of how image works in Android. In …

Read more

Android progress bar example

In Android, progress bar is useful to tell user that the task is takes longer time to finish. In this tutorial, we show you how to display a progress bar dialog to tell user that your task is running, and also how to increase the progress bar status until the task is completed. Note Refer …

Read more

Android analogclock and digitalclock example

In Android, the AnalogClock is a two-handed clock, one for hour indicator and the other for minute indicator. The DigitalClock is look like your normal digital watch on hand, which display hours, minutes and seconds in digital format. Both AnalogClock and DigitalClock are UNABLE to modify the time, if you want to change the time, …

Read more

Android time picker example

In Android, you can use “android.widget.TimePicker” class to render a time picker component to select hour and minute in a pre-defined user interface. In this tutorial, we show you how to render time picker component via android.widget.TimePicker in current page, and also in dialog box via android.app.TimePickerDialog. In addition, we also show you how to …

Read more

Android date picker example

In Android, you can use “android.widget.DatePicker” class to render a date picker component to select day, month and year in a pre-defined user interface. In this tutorial, we show you how to render date picker component in current page via android.widget.DatePicker, and also in dialog box via android.app.DatePickerDialog. In addition, we also show you how …

Read more

Android spinner (drop down list) example

In Android, you can use “android.widget.Spinner” class to render a dropdown box selection list. Note Spinner is a widget similar to a drop-down list for selecting items. In this tutorial, we show you how to do the following tasks : Render a Spinner in XML, and load the selection items via XML file also. Render …

Read more

Android rating bar example

In Android, you can use “android.widget.RatingBar” to display rating bar component in stars icon. The user is able to touch, drag or click on the stars to set the rating value easily. In this tutorial, we show you how to use XML to display a rating bar, few textviews and a button. When user click …

Read more

Android password field example

In Android, you can use “android.widget.EditText“, with inputType=”textPassword” to render a password component. In this tutorial, we show you how to use XML to create a password field, label field and a normal button. When you click on the button, the password value will be displayed as a floating message (toast message). P.S This project …

Read more

Android ToggleButton example

In Android, the “android.widget.ToggleButton” is a special class to render a button which has only two states, for example, “on and “off”. It’s best alternative to radio buttons to turn on or turn off a function. In this tutorial, we show you how to use XML to create two toggle buttons and a normal button, …

Read more

Android radio buttons example

In Android, you can use “android.widget.RadioButton” class to render radio button, and those radio buttons are usually grouped by android.widget.RadioGroup. If RadioButtons are in group, when one RadioButton within a group is selected, all others are automatically deselected. In this tutorial, we show you how to use XML to create two radio buttons, and grouped …

Read more

Android checkbox example

In Android, you can use “android.widget.CheckBox” class to render a checkbox. In this tutorial, we show you how to create 3 checkboxes in XML file, and demonstrates the use of listener to check the checkbox state – checked or unchecked. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. 1. Custom …

Read more

Android textbox example

In Android, you can use “EditText” class to create an editable textbox to accept user input. This tutorial show you how to create a textbox in XML file, and demonstrates the use of key listener to display message typed in the textbox. P.S This project is developed in Eclipse, and tested with Android 2.3.3. 1. …

Read more

Android : The connection to adb is down, and a severe error has occurred.

Problem Android development with Eclipse IDE, sometime it hit following “adb” error message and caused the application fail to start? [2011-11-22 15:17:07 – HelloWorld] —————————— [2011-11-22 15:17:07 – HelloWorld] Android Launch! [2011-11-22 15:17:07 – HelloWorld] The connection to adb is down, and a severe error has occured. [2011-11-22 15:17:07 – HelloWorld] You must restart adb …

Read more

Display different content if JavaScript is disabled

For security concern, many users like to disable JavaScript in their web browser, and it raise a big problem in many website which depends on JavaScript to function well. The easy and simple solution is using the HTML “noscript” tag to display different content if JavaScript is disabled. See following full “noscript” example : If …

Read more

The method getRealPath(String) from the type ServletRequest is deprecated

See following example to get the real server file path via servletRequest.getRealPath(“/”). However, warning is prompt and complained that this method is deprecated. import javax.servlet.http.HttpServletRequest; public class DisplayAction { private HttpServletRequest servletRequest; public String execute() { //The method getRealPath(String) from the type ServletRequest is deprecated String filePath = servletRequest.getRealPath("/"); } @Override public void setServletRequest(HttpServletRequest arg0) …

Read more

Android hello world example

In this tutorial, we show you how to create a simple “hello world” Android project in Eclipse IDE + ADT plugin, and run it with Android Virtual Device (AVD). The Eclipse ADT plugin provided easy Android project creation and management, components drag and drop, auto-complete and many useful features to speed up your Android development …

Read more

Check if variable is exists in JavaScript

In some cases, your JavaScript may need to depend on a particular variable to “define” or “exists”, in order to process on the next step. Note I don’t recommend to do so, as JavaScript shouldn’t involve any business logic, it should be purely basic validation or UI enhancement, but, many still like to code complex …

Read more

How to link an external JavaScript file

In this tutorial, we show you how to link an external JavaScript file (file extension end with .js) to web page. Note In HTML, you can either embed JavaScript on web page or external JavaScript file, or implemented both ways together. 1. External JavaScript file Create a new file end with “.js” file extension, and …

Read more

Google Maps API – Map Types example

Google Maps API support four map types : ROADMAP – Displays normal street/road map (default map type). TERRAIN – Display normal street/road map based on terrain information. SATELLITE – Display satellite images only. HYBRID – Mixed normal and satellite views, display street/road views on top of the satellite images. Note Normally, you just use either …

Read more

Google Maps API hello world example

A simple hello world guide to display Google Maps on a web page, via Google Maps Javascript API v3. In this tutorial, we show you how to display a map centered on “Malim Nawar, Malaysia” (my hometown), and use “marker (small icon)” to identify the location on the map. Full example… <html> <head> <title>Google Map …

Read more

Spring Security logout example

In Spring Security, to log out, just add a link to url “j_spring_security_logout“, for example : <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <html> <body> <h2>messages, whatever</h2> <a href="<c:url value="j_spring_security_logout" />" > Logout</a> </body> </html> In Spring security, declares “logout” tag, and configure the “logout-success-url” attribute : <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd"> <http auto-config="true"> <intercept-url …

Read more

Spring Security : Customize 403 access denied page

In Spring Security, if non authorized user try to access a protected page, a default “http 403 access denied” will be displayed : In this tutorial, we will show you how to customize 403 access denied page in Spring Security. 1. Spring Security Configuration Review a configuration, if “alex” try to access /admin page, above …

Read more

Spring Security access control example

In Spring Security, access control or authorization is easy to implement. See following code snippet : <http auto-config="true"> <intercept-url pattern="/admin*" access="ROLE_ADMIN" /> </http> It means, only user with authority of “ROLE_ADMIN” is allow to access URI /admin*. If non authorized user try to access it, a “http 403 access denied page” will be displayed. Spring …

Read more

Get HttpServletRequest via Maven repository

Problem Using Maven build tool, which jar should include to use HttpServletRequest or HttpServletResponse? Solution To use HttpServletRequest or HttpServletResponse in a development environment, include servlet-api. jar in your Maven pom.xml file. pom.xml <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> Put scope as provided, because most j2ee containers have this jar. You need this for complication …

Read more

ClassNotFoundException : DefaultSavedRequest

Problem Working with Spring Security, which jar contains DefaultSavedRequest? SEVERE: Exception loading sessions from persistent storage java.lang.ClassNotFoundException: org.springframework.security.web.savedrequest.DefaultSavedRequest at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) Solution DefaultSavedRequest is inside spring-security-web.jar. Visit this Spring Security hello world example for the list of dependencies libraries. <!– Spring Security & dependencies –> <dependency> <groupId>org.springframework.security</groupId> …

Read more

Spring Security password hashing example

In this tutorial, we will show you how to use BCryptPasswordEncoder to hash a password and perform a login authentication in Spring Security. In the old days, normally, we used MD5 Md5PasswordEncoder or SHA ShaPasswordEncoder hashing algorithm to encode a password… you are still allowed to use whatever encoder you like, but Spring recommends to …

Read more

Spring Security HTTP basic authentication example

When HTTP basic authentication is configured, web browser will display a login dialog for user authentication. This tutorial show you how to configure HTTP basic authentication in Spring Security. <http> <intercept-url pattern="/welcome*" access="ROLE_USER" /> <http-basic /> </http> Last Spring Security form-based login example will be reused, but switch authentication to support HTTP basic. 1. Spring …

Read more