Android学习(1)

来源:互联网 发布:java 线程共享变量 编辑:程序博客网 时间:2024/06/05 02:21

在Android还是1.1的时候就写过一些hello world的入门,一直没有时间深入学习。昨天把相关的环境都升级到了最新(1.5),试了一下Google官方提供的Demo:Notepadv1。

 

在学习的时候,碰到的问题:(http://docs.google.com/Doc?id=dgj5ns3n_1103cmqpvwhb)

(1)Syntax error on tokens, delete these tokens


(2)The type R is already defined
解决:
The new plugin creates a gen/ folder in your project, in which it puts the R.java file and all automatically generated AIDL java files. If you get an error such as The type R is already defined, then you probably need to delete your old R.java or your old auto-generated AIDL Java files in the src/ folder. (This does not apply to your own hand-crafted parcelable AIDL java files.)
以上两个问题的解决:
把src文件夹中除了Notepadv1.java和NotesDbAdapter.java外的文件都删除
(3)无法配置AVD
原因:
我的Project的API Level选择为Google APIs,但是创建AVD的时候,其target的API Level一直使用Android1.5,没有满足AVD的target的API Level大于或等于Project的API Level(http://www.javaeye.com/post/999920)
(4)两种定义id的方式
android:id="@android:id/list"
android:id="@android:id/empty"
The list and empty IDs are provided for us by the Android platform, so, we must prefix the id with android: (e.g., @android:id/list).
查看ListActivity的说明文档时,有下面一段话:

Screen Layout

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)

Optionally, your custom view can contain another view object of any type to display when the list view is empty. This "empty list" notifier must have an id "android:empty". Note that when an empty view is present, the list view will be hidden when there is no data to display.

android:id="@+id/text1"
In this case we create a new id called text1. The + after the @ in the id string indicates(表明) that the id should be automatically created as a resource if it does not already exist, so we are defining text1 on the fly and then using it.

 

另外,在阅读其官方文档的时候,发现了一个关于Activity lifecycle的图片,如下:

 

这个对于理解Activity应该很有用处。

 

代码就不单独贴出来了,晚上把它svn到Google Code上。

 

 

 

原创粉丝点击