How to do "Hello, Android"?

Ok, this time we are going to learn how to do a tipical "Hello, World!" and emulate it in a virtual Android OS.
The first step its this, when you have installed the SDK and the eclipse plugin we can to start.
Once you have the SDK installed you must link the SDK folder with the Eclipse plugin.
For this, do it:
Press Window>Preference... and then:



(Click for see picture bigger)
Then, create a new Android project and create a new class with any name. The class contains generated code, so i'm going to highlight the new code.
So, this is the code:


package com.example.android.apis;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class ApiDemos extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText("Hello dotNet, from Android");
        setContentView(tv);
      
    }
}


Then you must run it like a "Android aplication" and you'll get something like this:


(Click for see picture bigger)


Ok, this is all for now, if you can any question you can post a comment here, or you can write me at jessanmen1@gmail.com

Cheers!

Read Users' Comments (4)

4 Response to "How to do "Hello, Android"?"

  1. Anónimo Says:
    26 de enero de 2010, 1:12

    wow! It's easier than I tought. Thanks, I'm waiting the next post :-)

  2. Galeol says:
    18 de febrero de 2010, 4:17

    Hello!! Did you try to use xml files to get TextView and other elements?? It's the way Google advice to build android applications...
    Thanks for your blog!!

  3. Ángel says:
    23 de febrero de 2010, 9:54

    Hi Jesús!
    Guess who I am? I told you I'll visit your blog.
    What do think about Marco's idea? to found a "Mobile Development Club" at the ETSII, or directly a "Google Club" XD

    See you!

  4. Unknown says:
    18 de enero de 2011, 8:08

    Why did you write "tv.setText("Hello dotNet, from Android");"?
    dotNet = World? What the hell? =/

Publicar un comentario