0

Hey guys, I was wondering if someone could help me interpret line by line what is happening in this code...

package com.example.helloandroid;

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

public class HelloAndroid 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, Android");
       setContentView(tv);
   }
}

Edited by deceptikon: Fixed code tags

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by Syrne
0

I don't know much about Android development, but I know it's very similar to a 'normal' Java programming environment.

For this specific piece of code:

AFAIK,

super.onCreate(savedInstanceState);

is what returns information to the application in the event that an activity is interrupted (restart, detroyed, etc), if that makes sense.

In main, a 'tv' object is being created from the class 'TextView' which I am guessing is part of the Android SDK package.

Here it is: http://developer.android.com/reference/android/widget/TextView.html

a class-specific function is then called:

tv.setText("Hello, Android");

along with what looks to be pre-defined function with the object as an argument:

setContentView(tv);

I would suggest reading up on this site to learn as much as you can about the Android SDK:

http://developer.android.com/

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.