Category: Guides

Here you will learn how to convert a Numer String to different number types.
Each number type in Java has a parse method that allows you convert a string into the primitive type.

When converting a string to a number, the parse method may throw a NumberFormatException if the string is null or an invalid representation for that type.

Ok now why am I showing you this? let’s say you are pulling data from your DB but want to preform calculations on the values, unfortunately the number in the Strings are not ment to be final values and will give you odd numbers for calculations.
Please keep this in mind and take into consideration that an “int” and a “long” will only give you the full number and not the decimal point.

Convert a String to an int

To convert a String to an int, call the static method parseInt() on the Integer class. Below is an example:


String string = "123";
int value = Integer.parseInt(string);

Convert a String to a long
To convert a String to a long, call the static method parseLong() on the Long class. Below is an example:

String string = "123";
long value = Long.parseLong(string);

Convert a String to a float
To convert a String to a float, call the static method parseFloat() on the Float class. Below is an example:

String string = "123.4";
float value = Float.parseFloat(string);

 

Convert a String to a double
To convert a String to a double, call the static method parseDouble() on the Double class. Below is an example:

String string = "123.4";
double value = Double.parseDouble(string);
Here is an example from my code that shows a quick calculation of some sort
// Convert The060 String to Float for Calculations
float The060f = Float.parseFloat(The060);
int eight = 8;
int ten = 10;
int six = 6;</div>
<div>String TheVerdict = "";</div>
<div>

// Do Some Calculations
if (The060f &lt; six) {
TheVerdict = "It's One Amazing Ride!";
} else if (The060f &lt; eight &amp;&amp; The060f &gt; six) {
TheVerdict = "It's One Great Ride!";
} else if (The060f &lt; ten &amp;&amp; The060f &gt; eight) {
TheVerdict = "It's a Decent Ride....";
} else if (The060f &gt; ten) {
TheVerdict = "IT SUCKS!";
}

// Show AlertDialot with Monkey Thoughts
new AlertDialog.Builder( this )

Our First Useless Application – Hurray!

*** Wait – Quick Update ***
When I started writing this guide it was 2/2/2011 and we are at 2/23/2011, just too much travel and more….
I promise this will not happen again….

*** Wait Again ***
When I started this site I thought it would be simple for someone with basic development skills to write applications and guide other people, now I belive it’s not really the case… am I going to stop? no, not at all, I think you can still pick it up without a problem if you know some and uderstand the basics and if not you will learn as we progress, the only difference is that I don’t this my project here is a two month thing but more like a lifetime few months… now let’s move on

So after our first guide of setting up the project we will start developing on (if you didn’t read that start there – Linky) we are going to create our first useless application.
I’m going to skip the whole Hello World! Hello Android and move on if that’s ok with y’all to something a little less useless.

So what is the most important thing and priceless and most useless thing at the same time in the world?
I’m going to say time…. (correct me if i’m wrong but windows 7 was my idea and bare with me here)
So our first application is going to be a clock 🙂
Now that we have Eclipse open we will start in an odd way but after you learn you can take the lead on how and what.

First thing we are going to do is open our res/values/Strings.xml file

Read More »

So before I start writing our first useless app i’d like to start with the Android Project in Eclipse.
Remember the last guide of Eclipse? if not start here – linky

Open Eclipse
Hit File –> New –> Android Project
AndroidProjectNew

Now we will create out project without any activity (screen shot is connected to out next guide with our first application) we will discuss that
Project Name – Straight forward just give it your app name or something that will show up in Eclipse
Build Target – Now this is where you select your minimum android OS version that your application will support, i’m going to go with 1.6 and would not recommend going less then 2.1 as not all devices support 2.2 and up….
Application Name – This is the application name
Package Name – Now if we keep standards here we will use com.inrim.appname where we start with com. then your name or sites name in this case inrim. and then our application name E.G. com.inrim.uselessclock
Un-Check create activity we will get to that some day.
Hit Finish
AndroidProjectNew2

Now your new project will be created in Eclipse
AndroidProjectNew3

Let’s break it down on what holds what….
So after we create our project this is what we should get in our project’s root directory:
– AndroidManifest.xml, Main XML files that contains details on our application, components, activities, services and more that are going to be used in the application.
– build.xml, a script for compiling the application and installing it on our AVD or Android Device
– default.properties, our property file that is used by our app builder
– src/ folder contains our JAVA source codes
– res/ folder contains our GUI layour, graphics (Icons, Images ETC) and everything will be compiled with out application, please note that you will have three folder for graphics drawable-ldpi, drawable-mdpi, and drawable-hdpi we are not going to use them when we start developing (although it’s something that you will use sometime…)
As we are just starting out in Android development, you can get rid of all three of those directories and create a single drawable directory, putting your image in there.

Now Eclipse does not create all the folders that you might use like
– bin/ contains the application once it is compiled
– libs/ contains third-party Java JARs your application requires
– assets/ contains other files that you want to bundle with your application onto a device

So what no? what happened here?
We have our first project ready, but what can it do? (nothing much but let’s try something)
Right Clock your project –> Expand Run As –> Click Android Appliaction
AndroidProjectNew4

Your compatible AVD should launch, and…. nothing happens 🙂
AndroidProjectNew5

So hold on as we are going to dive in very shortly

So let’s start with we have an APP on the market for this site.
I must mention that I found this app through MobilityFreak.Co.Il (Great Mobil News site in Hebrew)

Link to the app (app brain)

http://chart.apis.google.com/chart?cht=qr&chs=150x150&chl=http://www.appbrain.com/app/com.warting.blogg.wis_inrim_feed_nu?install=appwidget

So now the how? very simple very easy and the idea is to stream your RSS feed into a mobile based content.
They are planning to release an iPhone version but I don’t know when or how easy it will be.
The service is FREE but please consider donations (as it’s free and a great service!)

Feed.nu makes it possible!

  • No programming skills needed
  • Instantly available

Follow this 5 simple steps and you are good to go.

  1. Register an account
  2. Log in and enter your feed in Feed settings
  3. You may want to upload your own custom images and change colors under Appearance (optional)
  4. Generate your own android app by clicking Android and then generate, wait a minute or two and then download your APK file.
  5. Upload your APK to Android Market

As for the Android Market, you will need to register as a Developer ($25 one time fee)
And then upload your APK (I will have a different post about this)

Here is a screen shot from the app
http://s2.appbrain.com/screen?id=-6473961073831477596&i=2

Ok, so now that you downloaded and installed the Android SDK and created your first AVD we need to move on to the Development environment.
Wait… you didn’t install the SDK??? Start here – Linky
So you will need to download and install Eclipse… What is eclipse? you can review their WIKI – Linky and here is a simple description on what they are…
Eclipse is an open source community, whose projects are focused on building an open development platform comprised of extensible frameworks, tools and runtimes for building, deploying and managing software across the lifecycle. The Eclipse Foundation is a not-for-profit, member supported corporation that hosts the Eclipse projects and helps cultivate both an open source community and an ecosystem of complementary products and services.

Step 2 – Download and install Eclipse environment
Open Eclipse Website – Linky
Now download Eclipse IDE for Java Developers, based on the OS you have
eclipse

Now on the download page either download via HTTP or Torrent, more links are on the page (I wanted a smaller screen shot)
eclipsedownload

After the download is completed extract the content of the file to a folder you want to work in.
In my case it was C:\Android\Eclipse
And run the eclipse.exe main application from where you extracted it to
eclipse1

Hit Continue Reading to move on…
Read More »