Android – Notepad Tutorial: Exercise 1

Notepad Tutorial Overview
Notepad Tutorial: Exercise 1

This tutorial is exciting for the novice, but limited with respect to new knowledge. The impression I got when going through it was that it’s more to show you what you can do with some basic components of the Android SDK. I will go into depth on some of the things talked about later as I get through more tutorials Databases being one of the big ones I want more explanation on. So keep that in mind as you go through this tutorial. It’s a bird’s eye view tutorial in my opinion.

The First issue I had was when I got to step 8. I entered


But I got the following error in Eclipse: “notepad_list cannot be resolved or is not a field”. I didn’t really see what the problem was for a while, but after some further investigation I found something. In the imports section you can see

import android.R;

This imports Android’s R class. What we want is our R class located in the “gen” folder. How do we do this? Simple. Just remove that import and it will automatically revert to your R class.

FYI: If you are using Eclipse and you are using the CTRL+SHIFT+O to bring in the required imports, make sure that it doesn’t accidently import Android’s R class again. If you see some problems with your resources such as the above “cannot be resolved or is not a field” error then check to see if this import snuck its way in.

Otherwise this tutorial is straightforward. They give you most of the code fragments so you can pretty much copy and paste if you wanted. As usual it’s better to type it out so that you’ll hopefully remember it better.

Categories: Android, Java, Mobile, Programming

Android – Views Introduction

Views Tutorials

Next are the Views Tutorials. Coming from a web development standpoint, I like to think them as the layout tutorials.

Views Tutorials

The tutorials are fairly easy to follow as some of them are just a more advanced Hello World tool. I only have a couple of comments.

If you are like me you don’t have any icons prepared at the time of these tutorials so I ended up using the one icon that comes with the installed SDK: res/drawable-mdpi/icon.png. On the Grid tutorial, you will create a class called ImageAdapter. In this class you create an array that references some image icons for the tutorial. The code from the AD website references many icons, but I only had so I just reused it for all of my images for this grid tutorial. I changed the entire arrays contents to be “R.drawable.icon” for each element within the array.

private Integer[] mThumbIds = {
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon

No I would never do this in a real application, but just for tutorials sake and the fact I didn’t want to go find any icons, I used the same icon. You will also notice that if you try and keep the image references from the tutorial that you will get an error saying those resources don’t exist. If you have some icons you want to use it is very simple to add to the application. Simply place them in the res/drawable-mdpi/ folder and now you can access them like this:


Don’t include the image’s file extension when you reference it in your code.

You’ll come up with a similar issue on the tab layout tutorial. In the Tab tutorial you’ll find something new. You create 3 new classes that are of type Activity. In order to get the application to run you will need to edit the AndroidManifest.xml document for your project by defining these Activities within that file. To understand why, read the section titled “The Manifest File” at this URL.


Before this point I hadn’t edited the Manifest file or read about it too any significant extent so I had to do some research on how to fix this tutorial and get my app running. I found this link which showed me how to set up my manifest file:


My Manifest file ended up looking like this:

Make sure you have all of your activity names and package name correct within the manifest file.

Other than that I didn’t have any significant issues with the Views tutorials.

Categories: Android, Java, Mobile, Programming

Android – Hello World

Hello World Tutorial

Android Developer Hello World
Hackaday Hello World

The above links give you’re the same result. The AD site will overlap some of the information from my previous post, but that’s okay because you might have gotten stuck or missed something.
Before proceeding with this tutorial I recommend the following reading.

I know it may be a little boring, but it is quite informative and contains clear explanations of Android terminology. That will make your going a little smoother as you progress. I’ve been referring to it often my first week as I’ve been roaming through tutorials.

On the AD site, you’ll finish the tutorial after you’ve read half of the article, but the bottom half contains a lot of important information. If you want to move on then you’ll be okay, but I strongly recommend you read on. In fact I wouldn’t even say it’s optional if you’re serious about becoming an honest to goodness Android developer.

The bottom of the article contains links that tell how to develop from the command line or in other IDE’s. I have not investigated those articles and I probably won’t because I find Eclipse to be a very smooth sailing IDE for Android development.

One final note – as you read through the tutorials you’ll come across the res/values/strings.xml file. This file lets you define any strings that will be used in your app rather than hardcoding them into your application. According to best practices for development, it is recommended that you make use of this file. You can access these strings from your Java files like this:


This returns an int value – not a string. The reason is that your strings are indexed and retrieved by index through the Android API. In other words you as the user don’t need to worry about converting it to a string in some way, the API does it for you. You just reference it like above and the API does the rest.
From your layout xml files you can access these string values like this:


So for a real example:

Categories: Android, Java, Mobile, Programming

Developing for Android – The Beginning

I decided I wanted to start doing some mobile development since it’s in very high demand right now. My first thought was I would learn some Objective C and write an app for my iPad. I soon discovered that I need to have a Mac to do that. I know there are some SDK’s that allow you to develop on Windows, but something just didn’t sit right with me doing that at this point in time so I decided to go for Android devices. No I don’t have an Android device, but I can develop for it in Windows and the emulator that comes with the SDK is sufficient to get my hands dirty.

Here are the setup instructions: Android SDK Setup
Alternative, but virtually identical set up instructions can be found here: Hackaday Android SDK Setup

Both resources are clear, but if there is any confusion the other clears it up pretty easy.
I am using Eclipse since that is the IDE that seems to be preferred by the Android Developers crew. If you really don’t want to use Eclipse they have instructions on how to help you get set up. Personally, I think using Eclipse has been simple and straightforward. Roughly speaking, here are the basic steps to install.
1. Install Eclipse Eclipse Download . Eclipse classic is the preferred version.
2. Download and install the Android SDK (the link is above).
3. Install the ADT plugin for Eclipse and Android platforms. Eclipse

That will get you going. My steps listed are meant to give you an idea of what’s involved in the initial setup and not as a step by step guide, so refer to the first two links I posted above when you get lost.
Don’t forget to create your virtual emulator from the Android SDK and AVD Manager. You’ll need to do some configuring in Eclipse to integrate it. The instructions are pretty clear on how to do this from the above links. Also when you launch the emulator you’ll probably feel that the screen is too small. To change the resolution this site has some simple instructions:

Adjust Emulator Screen

The link directly below will help a lot as well. It’s you standard Hello World tutorial which I’ll talk about in my next post. It also helps you sort things out that we talked about in this post.

Android Hello World Tutorial

Categories: Android, Java, Mobile, Programming

Get HTML Element’s Absolute Position

January 1, 2011 Leave a comment

I have been working with the new HTML5 canvas element and found that x and y coordinates within the canvas are relative to the canvas. So what’s the significance of this? I created a simple drawing app using javascript on the ipad, but when I retrieved the coordinates, I got the page’s coordinates instead of the coordinates relative to the canvas. So if my canvas is 200 px in height and it’s halfway down the page at an absolute position of y: 600px, when I try and trieve the touch y coordinate I get a return value of 600+px. Relative to the canvas, it won’t make a stroke on the canvas since my limit is 200px. Using the above javascript functions to find the absolute position I simple retrieved the coordinates I was getting minus the absolute coordinates of my canvas. This gave me the coordinates I needed to get a nice canvas strokes.

Categories: Javascript

Display Driver Configuration on Linux

August 30, 2010 Leave a comment

Sometimes while building a Linux image or simply configuring a new display driver, there are issues with display drivers that can cause the X server to stop altogether. This will cause the machine to display a command prompt.

Possible Solutions:

1. Use the command ‘startx’. For some reason the X server may have just hiccuped.

2. If the display driver is from nvidia try the ‘nvidia-xconfig’ command to generate a new X configuration file and then use ‘init 3; init 5’ to quasi-restart the machine which may start X properly.

3. Copy an X configuration file (/etc/X11/xorg.conf) from a working machine if the OS and architecture are similar to the machine in question (No guaranteed stability).

(Most likely not an ‘at home’ solution)
4. Image the machine to a known working image (Altiris).

If you update your kernel there is a good chance you will have to rebuild (reinstall) your graphics driver. The graphics driver uses the kernal libraries in its building. So if the kernel gets updated, the graphics driver will need to be updated. Otherwise, once you restart your computer your graphics driver will be out of date and your X server may not start.

Categories: Linux

How to take a screenshot in Linux

In a terminal use the command ‘import’:

[user5@server3 ~]$ import myscreenshot.png

A crosshairs should come up in place of your mouse. You can then click and drag to select the area of the screen you want a screenshot of.

Categories: Linux