Tampilkan postingan dengan label sample. Tampilkan semua postingan
Tampilkan postingan dengan label sample. Tampilkan semua postingan

Jumat, 04 Maret 2011

Reader Feedback: Analysis of an Exercise

At the end of each "Hour" in the Sam's Teach Yourself Android Application Development in 24 Hours book, there are exercises. We originally designed these exercises to be items people could try to extend their knowledge above and beyond what was learned verbatim in the chapter, given some hints and practice using the the Android documentation that is critical to become familiar with.

Here we present one such exercise that occurs in one of the first real coding hours and present our thought process for determining the solution. Hopefully this will help readers who may be struggling with the difficulty of the exercises. That said, we have also determined, based upon reader feedback, that a handful of exercises in the book are perhaps unfairly difficult. For the next edition of the book, many of these will be replaced or labelled as challenge exercises.

Walk-Through of an Exercise

This is from Hour 7 on page 125, if you'd like to follow along. As it's the end of the chapter, you already would have downloaded the code to work along with in the chapter. If not, it's available right here.
"Exercise #1: Modify the LayoutAnimationController in the QuizSplashActivity class to apply animations of each child view within a TableRow control in random order by using the setOrder() method with a value of 2 (random)."
Key Phrase #1: "Modify the LayoutAnimationController in the QuizSplashActivity"

Thought Process, Step 1: This tells me we're dealing with something to do with the LayoutAnimationController. Luckily, we just covered that on page 122, where we gave this following code:

Animation spinin = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
LayoutAnimationController controller = new LayoutAnimationController(spinin);
TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
for (int i = 0; i < table.getChildCount(); i++) {
    TableRow row = (TableRow) table.getChildAt(i);
    row.setLayoutAnimation(controller);
}

Thought Process, Step 2: The code goes in QuizSplashActivity. Since I'm in Hour 7, I've been implementing this activity for the Splash Screen for most of the chapter.

Key Phrase #2: "to apply animations of each child view within a TableRow control"

Thought Process, Step 3: So far so good. The code is already doing that. We found the code in the section labelled, "Animating All Views in a Layout."

Key Phrase #3: "in random order"

Thought Process, Step 4: Hmm, I don't know how to do that. Let me read on, finishing the sentence...

Key Phrase #4: "using the setOrder() method with a value of 2 (random)."

Thought Process, Step 5: Oh, that's how! OK, hold on. I have two options: I could look up this method in the Android SDK docs, or just write it based on what was said in the exercise and see what happens. (Note: We prefer you look it up, like a good student, but experimentation doesn't hurt anything, either.) But perhaps we're lazy so... Let me just add that one line of code to the end of the initial listing, which will now look like:
Animation spinin = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
LayoutAnimationController controller = new LayoutAnimationController(spinin);
TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
for (int i = 0; i < table.getChildCount(); i++) {
    TableRow row = (TableRow) table.getChildAt(i);
    row.setLayoutAnimation(controller);
}
controller.setOrder(2); // THIS IS THE ONE NEW LINE OF CODE, THE SOLUTION TO EXERCISE #1

Run the app and see what happens.... Hey! That's pretty neat. Each time I run it, the animations happen in a different order and sometimes some of them happen at the same time.

Senin, 30 Agustus 2010

Reader Feedback: Trivia Quiz Server Bug

Bugs happen! 

In Hour 17 of Sam's Teach Yourself Android Application Development in 24 Hours, you learn about AsyncTasks. You use one to send a request to the server to add a friend based upon their email address. What's supposed to happen is that the server looks up the email address and if it finds a match, it adds that user to your list of friends, which is stored on the server. Then, when the Scores Screen is updated to download scores of your friends, the server will return XML containing just that. It will not return email address or anything like that -- we don't want privacy leaks.

What was happening?

Nothing!

Nothing? That's right. The server was failing to find any friends -- regardless of the email address. It was, however, returning the correct status. We just didn't bother with doing anything more with the status than printing it out to LogCat. Whoops.

Fixed

The fix was simple. The Google App Engine server has been updated to version 3 and, after some brief testing, we promoted this to the default server.

If you were having trouble with adding friends, now you know why.

This report was sent in by a reader. If you have troubles, please don't hesitate to contact us at androidwirelessdev@gmail.com or right here on this blog. We see all comments. It might just be a bug!
ANDROID BOOK © 2008 Template by:
SkinCorner