Android code , Android Phone, Android Developers

Android code , Android Phone, Android Developers and New Google Android Technologies

Archive for November, 2010

TIP Part 2

Posted by admin November - 22 - 2010 - Monday ADD COMMENTS

Considering that the setContentView( ) method is being told to set main.xml as the
current View, and main.xml contains a TextView that says “Hello World, HelloWorldText,”
it may be safe to assume that compiling and running HelloWorldText now will give
you your Hello World! application. To test this, run your unaltered HelloWorldText
application. Choose Run | Run to open the Run As dialog box, select Android Application,
and click OK.

The new project you just established contains the code to create a Hello World!
application on its own. However, that is not very engaging, nor does it teach you very
much about programming an Android application. You need to dissect the project and
see exactly how the project displayed the “Hello World!” message.
What happened when you created the new Android project is that the Android plugin
modified main.xml. This is a perfect example of one way to modify the UI in Android.
The following lines of code are added to main.xml by the Android SDK when the project
is created:
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Hello World, HelloWorldText”
/>

TIP

Posted by admin November - 9 - 2010 - Tuesday ADD COMMENTS

If you do not see the android.os.Bundle import statement in your project, expand the
tree within your development window. Eclipse rolls up all the import statements under
the first one, so you must expand the tree to see the rest of them.
Focusing now on your class HelloWorldText, you can see that it extends the Activity
class. Activity is imported from the previous lines. All applications derive the Activity class,
and this derivation is required for running an application on Android. For something to
run and be displayed on the screen, it must be derived from Activity.
The HelloWorldText class holds the code needed to create, display, and run your
application. Right now there is only one method in your HelloWorldText class that is
defined with code in it, onCreate( ).
The onCreate( ) method takes in icicle as a bundle. That is, all of the current
state information is bundled as an icicle object and held in memory. You will not be
directly handling icicle in this application, but you need to be aware of its presence
and purpose.

The next line in the file is the one that really does some perceptible action:
setContentView(R.layout.main);
The method setContentView( ) sets the Activity’s content to the specified resource.
In this case, we are using the main.xml file from the layout directory via the pointer in
the R.java file. The main.xml file, right now, contains nothing more than the size of the
HelloWorldText screen and a TextView. The TextView is derived from View and is used
to display text in an Android environment. Reviewing the contents of main.xml, you can
see that it contains the following line:
android:text=”Hello World, HelloWorldText”