﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-awaycatalongfish</title><link>http://www.blogjava.net/awaycatalongfish/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 03 May 2026 04:31:02 GMT</lastBuildDate><pubDate>Sun, 03 May 2026 04:31:02 GMT</pubDate><ttl>60</ttl><item><title>Creating Your First Program</title><link>http://www.blogjava.net/awaycatalongfish/archive/2011/05/09/349834.html</link><dc:creator>不爱吃猫的鱼</dc:creator><author>不爱吃猫的鱼</author><pubDate>Mon, 09 May 2011 05:51:00 GMT</pubDate><guid>http://www.blogjava.net/awaycatalongfish/archive/2011/05/09/349834.html</guid><wfw:comment>http://www.blogjava.net/awaycatalongfish/comments/349834.html</wfw:comment><comments>http://www.blogjava.net/awaycatalongfish/archive/2011/05/09/349834.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/awaycatalongfish/comments/commentRss/349834.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/awaycatalongfish/services/trackbacks/349834.html</trackback:ping><description><![CDATA[ADT comes with a built-in example program, or template, that we&#8217;re<br />
going to use to create a simple &#8220;Hello, Android&#8221; program in just a few<br />
seconds. <br />
ADT带有内置的例子和模板,我们可以在几秒钟内创建一个简单的"Hello android"的例子<br />
<br />
Get your stopwatch ready. Ready? Set? Go!<br />
准备好秒表,ready?go<br />
<br />
Select File &gt; New &gt; Project... to open the New Project dialog box. Then<br />
select Android &gt; Android Project, and click Next.<br />
<br />
Enter the following information:<br />
Project name: HelloAndroid<br />
Build Target: Android 2.2<br />
Application name: Hello, Android<br />
Package name: org.example.hello<br />
Create Activity: Hello<br />
Min SDK Version: 8<br />
When you&#8217;re done, it should look something like Figure 1.3, on the next<br />
page.<br />
Click Finish. The Android plug-in will create the project and fill it in<br />
with some default files.<br />
&nbsp;单击 finish,android的插件就会创建一个工程<br />
<br />
Eclipse will build it and package it up so it will<br />
be ready to execute. If you get an error about missing source folders,<br />
select Project &gt; Clean to fix it.<br />
OK, that takes care of writing the program; now all that&#8217;s left is to try<br />
running it. First we&#8217;ll run it under the Android emulator.<br />
<p>1.3 Running on the Emulator<br />
To run your Android program, go to the Package Explorer window,<br />
right-click the HelloAndroid project, and select Run As &gt; Android Appli-<br />
cation. If you&#8217;re following along in Eclipse, you may see an error dialog<br />
like the one in Figure 1.4, on page 25. This indicates we haven&#8217;t told<br />
the emulator what kind of phone to emulate.<br />
Creating an AVD<br />
To do this, you need to create an Android Virtual Device (AVD) using<br />
6<br />
either Eclipse or the android avd command. It&#8217;s easier to use Eclipse,<br />
so select Yes in the AVD Error dialog to open the AVD Manager. You can<br />
open the manager again later by selecting Window &gt; Android SDK and<br />
AVD Manager.<br />
6. http://d.android.com/guide/developing/tools/avd.html<br />
Report erratum<br />
this copy is (P1.0 printing, July 2010)</p>
<p>RUNNING ON THE EMULATOR 24<br />
Figure 1.3: New Android project<br />
Report erratum<br />
this copy is (P1.0 printing, July 2010)</p>
<p>RUNNING ON THE EMULATOR 25<br />
Keeping Up with the Plug-In<br />
The Android Eclipse plug-in is a work in progress that changes<br />
much more often than the Android SDK. The version you down-<br />
load may be different from the one I used when writing this<br />
book, and it may contain a few, shall we say, idiosyncrasies. I<br />
recommend you check the plug-in site monthly to pick up any<br />
new features and fixes.<br />
Figure 1.4: Missing Android Virtual Device (AVD)<br />
Click the New... button, and then fill out the fields for the new AVD as<br />
follows:<br />
Name: em22<br />
Target: Android 2.2 - API Level 8<br />
SDCard: 64<br />
Skin: Default (HVGA)<br />
This tells Eclipse to set up a generic device called &#8220;em22,&#8221; which has the<br />
Android 2.2 (FroYo) firmware installed. A 64MB virtual Secure Digital<br />
(SD) card will be allocated, along with a half-VGA (320&#215;480) display.<br />
When you are done, you should see something like Figure 1.6, on<br />
page 27. Because of updates in the SDK tools since this was written,<br />
your screen may look slightly different.<br />
Click Create AVD to create the virtual device. A few seconds later you<br />
should see a message that the device has been created. Click OK, select<br />
the AVD, and then click Start... and then Launch to bring it up. Close<br />
the AVD Manager window when you&#8217;re done.<br />
Report erratum<br />
this copy is (P1.0 printing, July 2010)</p>
<p>RUNNING ON THE EMULATOR 26<br />
Cupcake vs. Donut vs. Eclair vs. FroYo<br />
TheversionofAndroidrunningonyouremulator(orrealphone)<br />
mustbecompatiblewithyourprogram&#8217;sbuildtarget.Forexam-<br />
ple, if you try to run an Android 2.2 (FroYo) program on an<br />
Android 1.5 (Cupcake) phone, it won&#8217;t work because Android<br />
1.5 phones can only run 1.5 or earlier programs. Android 2.2<br />
phones, on the other hand, can run programs built for 2.2, 2.1,<br />
2.0.1, 2.0, 1.6, 1.5, and earlier. But it may be a while before most<br />
phones have been upgraded (if ever).<br />
So, why not just target Android 1.5? Unfortunately, applica-<br />
tions built for 1.5 don&#8217;t always display correctly on the larger<br />
and smaller screens found on 1.6 phones. Luckily, there&#8217;s an<br />
easy way to make your programs compatible with all versions<br />
of Android. See Chapter 13, Write Once, Test Everywhere, on<br />
page 256 for instructions.<br />
Figure 1.5: Running the &#8220;Hello, Android&#8221; program<br />
Report erratum<br />
this copy is (P1.0 printing, July 2010)</p>
<p>RUNNING ON THE EMULATOR 27<br />
Figure 1.6: Creating an AVD in Eclipse<br />
Report erratum<br />
this copy is (P1.0 printing, July 2010)</p>
<p>RUNNING ON A REAL PHONE 28<br />
Shortening the Turnaround<br />
Starting the emulator is expensive. Think about it this way—<br />
when you first turn on your phone, it needs to boot up just like<br />
anycomputersystem.Closingtheemulatorisjustliketurningoff<br />
the phone or pulling the batteries out. So, don&#8217;t turn it off!<br />
Leave the emulator window running as long as Eclipse is run-<br />
ning. The next time you start an Android program, Eclipse will<br />
noticetheemulatorisalreadythereandwilljustsenditthenew<br />
program to run.<br />
Let&#8217;s Try That Again<br />
Once you have a valid AVD, the Android emulator window will start up<br />
and boot the Android operating system. The first time you do this, it<br />
may take a minute or two, so be patient. You may need to right-click<br />
the project and select Run As &gt; Android Application again. If you see<br />
an error message saying that the application is not responding, select<br />
the option to continue waiting. If you see a key guard screen, swipe it<br />
as directed to unlock.<br />
Eclipse will send a copy of your program to the emulator to execute.<br />
The application screen comes up, and your &#8220;Hello, Android&#8221; program is<br />
now running (see Figure 1.5, on page 26). That&#8217;s it! Congratulations on<br />
your first Android program.<br />
1.4 Running on a Real Phone<br />
Running an Android program on a physical device such as the Droid<br />
or Nexus One during development is almost identical to running it on<br />
the emulator. You need to enable USB debugging on the phone itself<br />
(by starting the Settings application and selecting Applications &gt; Devel-<br />
opment &gt; USB Debugging), install the Android USB device driver if you<br />
haven&#8217;t already (Windows only), and then plug the phone into your com-<br />
7<br />
puter using the USB cable that came with the phone.<br />
7. See http://d.android.com/guide/developing/device.html for the latest device driver and<br />
installation instructions.<br />
Report erratum<br />
this copy is (P1.0 printing, July 2010)</p>
<p>FAST-FORWARD &gt;&gt; 29<br />
Close the emulator window if it&#8217;s already open. As long as the phone is<br />
plugged in, Eclipse will load and run applications on the phone instead.<br />
When you&#8217;re ready to publish your application for others to use, there<br />
are a few more steps you&#8217;ll need to take. Chapter 14, Publishing to the<br />
Android Market, on page 271 will cover that in more detail.<br />
1.5 Fast-Forward &gt;&gt;<br />
Thanks to the Eclipse plug-in, creating a skeletal Android program<br />
takes only a few seconds. In Chapter 3, Designing the User Interface, on<br />
page 43, we&#8217;ll begin to flesh out that skeleton with a real application—a<br />
Sudoku game. This sample will be used in several chapters to demon-<br />
strate Android&#8217;s API.<br />
But before delving into that, you should take a few minutes to read<br />
Chapter 2, Key Concepts, on the following page. Once you grasp the<br />
basic concepts such as activities and life cycles, the rest will be much<br />
easier to understand.<br />
Although the use of Eclipse to develop Android programs is optional, I<br />
highly recommend it. If you&#8217;ve never used Eclipse before, you may want<br />
to invest in a quick reference such as the Eclipse IDE Pocket Guide<br />
[Bur05].</p>
<br />
<img src ="http://www.blogjava.net/awaycatalongfish/aggbug/349834.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/awaycatalongfish/" target="_blank">不爱吃猫的鱼</a> 2011-05-09 13:51 <a href="http://www.blogjava.net/awaycatalongfish/archive/2011/05/09/349834.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java 集合概述</title><link>http://www.blogjava.net/awaycatalongfish/archive/2011/05/04/349504.html</link><dc:creator>不爱吃猫的鱼</dc:creator><author>不爱吃猫的鱼</author><pubDate>Wed, 04 May 2011 08:16:00 GMT</pubDate><guid>http://www.blogjava.net/awaycatalongfish/archive/2011/05/04/349504.html</guid><wfw:comment>http://www.blogjava.net/awaycatalongfish/comments/349504.html</wfw:comment><comments>http://www.blogjava.net/awaycatalongfish/archive/2011/05/04/349504.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/awaycatalongfish/comments/commentRss/349504.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/awaycatalongfish/services/trackbacks/349504.html</trackback:ping><description><![CDATA[Java的集合大致可分为:Set List Map三种,其中Set表示无序\不可重复的集合.List表示有序重复的集合.Map表示具有映射关系的集合
<img src ="http://www.blogjava.net/awaycatalongfish/aggbug/349504.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/awaycatalongfish/" target="_blank">不爱吃猫的鱼</a> 2011-05-04 16:16 <a href="http://www.blogjava.net/awaycatalongfish/archive/2011/05/04/349504.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>