Hello World, Part 1
The wife is watching horrible reality shows, the baby is sleeping. Here we go:
Eclipse is quite cluttered at first glance. The tutorial guides you how to create a project with screenshots and all. Nice. Click, click.
Hmm, namespace. That sounds important. What it is, exactly? Lets ask Wikipedia:
http://en.wikipedia.org/wiki/Namespace_(computer_science)
- there is a Java section.
If I understand correctly, I might as well create a private namespace for myself. Offkey Development (long story).
Am I going off a tangent here? Correct me if I am wrong.
Back to the tutorial. Damn. The tutorial is outdated - the new version of Eclipse is different. Oh, well, you live and learn. Wonder what happens if I click next? Ah, that seems more like it. Version 2.1 pleas... oh.
Both a Google Inc version and an Open Source version. Open source is something with free beer, IIRC. Sounds good. Next.
Hmm, package name, namespace. I need to read up on this. Onwards. Finish.
Er.. What now? Eclipse has created a package which expands into a tree. Its all Greek to me at the moment, and I don't speak Greek. The tutorial tells me to open HelloAndroid > src > com.example.helloandroid (which I changed to com.example.offkeydevelopment). Oooh! Java code.
I can already see that my laptop's 1920x1080 diplay is my friend in this Epic Journey.
A bunch of automatically generated code lines. I want to understand this. Here they all are:
Code:
package com.example.offkeydevelopment;
import android.app.Activity;
import android.os.Bundle;
public class
HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView
(R.layout.main);
}
}
I will go through them one by one, and write what I think each of them does. If I make mistakes, please correct me.
Code:
package com.example.offkeydevelopment;
Package name again. What does it really mean?
Code:
import android.app.Activity;
import android.os.Bundle;
Here we import the needed classes. Get it. Is classes the right word?
Code:
public class HelloAndroid
Name of the class. What is the diffence between public and private here?
Android splits applications into Activities, right?
Override? Is this some sort of message to the OS about interrupts?
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Now I am struggling. What does this do? And what does public void mean? I have seen it before. Wikipedia?
Google? Hmm, OK, it has to do with how the application communicates with other applications, right? Or wrong?
Does someone have a link which explains this in an easy to understand way?
Code:
setContentView(R.layout.main);
Set content view. At least I get that
Whew. My head hurts, and I have not even started coding yet. Oh well, the horrible reality show is still on, and on screen right now is one of the ugliest women I have ever seen.
More code! Or really, my very first line:
Code:
import android.widget.TextView;
I need to import a package, and this line does it for me. OK. Eclipse has a nice autocomplete. It already like it and want to be friends with it.
Code:
TextView tv = new TextView(this);
TextView is a subclass that handles views. Here, I create a TextView called tv and gives (this) as context reference. I can use (this) because Activity inherits from Context, and my class is a subclass of Activity.
I think I mostly get it.
Code:
tv.setText("Hello, Android");
Here I define the content of tv.
Here, I tell setContentView, which displays th UI, to use tv.
Let's run it. Run - Run. Hello self. It works. Hooray

So, I should be able to simply change the content of my tv.setText statement. Yep.
That went rather well, all in all. Next time, I dive into xml. Today, I hardcoded the UI. Not nice, according to the tutorial, it can be defined in XML instead.