Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 2 Application Development
|
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2010, 11:41 AM
Registered User
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Chapter 2, Understanding HelloWorld is insufficient.

I'm going to report back my confusions along the way as I learn Android development in 2010. My hope is the Author will be reminded what it is like to to start learning this stuff and that the feedback will help the next version.

So the Hello World program is usually presented as a chance to see and understand a minimal working program. But Chapter 2 misses the chance to explain how HelloWorld works and start explaining the types of Android Applications. This is a big mistake because a novice reader wants to be assured that they can understand HelloWorld before they tackle the further chapters. Some people are reading to help decide if they want to do Android, or iPhone programming.

I could figure out:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

but I had to refer to http://java.sun.com/docs/books/tutor.../override.html
to understand "@Override". I remembered "super" from past Java days.

However Listing 2.2 was a puzzle.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>

Even without having read Chapter 4, I think a brief description is in order. My immediate questions were:

1) What is "TextView" ? Is it a reserved word or a label chosen by the programmer ? ( I'm leaning towards reserved word seeing as listing 2.3 has the snippet new textView(this) )

2) What is going on here? android:text="@string/hello"
Is @string a reserved word ? Why the /

3) What is a LinearLayout anyhow?



So I run the program and it displays "Hello World HelloWorld", but I'm not clear how this output was generated. Must have come from:

setContentView(R.layout.main);

So two obvious questions:

setContentView is a method from what class ?

What is the type of R.layout.main ?
and where is R defined anyhow ?

My answers come slowly:
R is defined in the gen folder. Aha, The XML resources are used to generate Java source. Perhaps that is what the book calls "inflating", see Chapter 3.

So main is the int 0x7f030000
and therefore via http://developer.android.com/referen.../Activity.html

public void setContentView (int layoutResID)
Set the activity content from a layout resource.
The resource will be inflated, adding all top-level views to the activity.

So what is so special about 0x7f030000? Is there a link between 0x7f030000 and the main.xml layout ?


Alright, so how did "Hello World HelloWorld" appear?

It looks like the TextView widget has text of android:text="@string/hello"
I guess "hello" is a label for some other resource perhaps defined in strings.xml ?

Hmm, If I double click on strings.xml, and then click on hello I see:
Name: Hello
Value: Hello World HelloWorld!


So I guess the answer is:

setContentView(R.layout.main); somehow links to main.xml
which must describe the layout of the application,
and has a TextView Widget that has text contained in a resource
which was defined to be "Hello World HelloWorld!"
 
Old July 2nd, 2010, 10:12 PM
Registered User
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Better Hello World explanation

I found a decent explanation here:
http://developer.android.com/resourc...llo-world.html
 
Old July 14th, 2011, 01:04 PM
Registered User
 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default This Isn't A Beginner's Book

Hi.
I know your post was made a year ago, but I wanted to take a second to add something to your post. This book is good. However, it is not a beginner's book. You might need Beginning Android Development, instead of Professional Android Development to answer some of your early questions. Also, this book IS NOT a Java primer. Some of the issues you raised stem from not knowing Java well. It is truly worth reading the Java docs online at the Oracle website BEFORE you read this book so that you can understand class structure, java semantics, etc.

One book can't be all things to all people, but this book is exactly what it needs to be for it's intended audience. Unfortunately, that means that it might not answer all of the questions a newbie might have. So, if I might suggest a course of action:

1. Read the online java documents on the Oracle website (free online learning)

2. Read the online android documentation on the Google website (free online learning)

3. Read the Beginning Android Development book

4. Read the Professional Android Development Book

That should give you a good understanding of Java and Android programming.
Hope this helps someone in the future.
 
Old July 14th, 2011, 01:48 PM
Registered User
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Just wanted to make a good book better

I did get my Android modules done last year. I'm not doing any Android programming this year.

The "Whom This Book Is For" section does say:

"While knowledge of Java is helpful, it's not a necessity"





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10 HelloWorld function ChuckASP BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 April 2nd, 2010 03:39 PM
Chap 9 HelloWorld Plug problems. chucknb28409 BOOK: Professional Joomla! ISBN: 978-0-470-13394-1 2 June 26th, 2009 07:33 PM
problem in helloworld progarmme in chapt 18 clnbabu BOOK Beginning Linux Programming, 3rd Edition 0 August 25th, 2007 03:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.