day1

ADT: Android Development Tools
Context:Activity继承于Context
Activity:Oncreate(),setContentView()
TextView:构造的时候需要一个Context;setText(CharSequence text)
CharSequence:This interface represents an ordered set of characters and defines the methods to probe them.

----------------------------------------------------------------------------
1  Create a New Android Project:
Project Name :工程名
Application Name :应用名;最终显示在模拟器上。(the string is defined in the res/values/strings.xml file and referenced by your AndroidManifest.xml file)
Package Name :
Create Activity :插件创建的Activity名。Activity是一个应用程序的基础。  通常是Android Activity的子类。
Min SDK Version :最低Api说明

-----------------------------------------------------------------------------
2  程序说明:
Notice that the class is based on the Activity class. An Activity is a single application entity that is used to perform actions. An application may have many separate activities, but the user interacts with them one at a time. The onCreate() method will be called by the Android system when your Activity starts — it is where you should perform all initialization and UI setup. An activity is not required to have a user interface, but usually will.

Activity是一个应用实体,用于处理action。
当 Activity 开始的时候,Android System 将会调用其中的OnCreate()方法  ;   setContentView()


3 UI:

An Android user interface is composed of hierarchies of objects called Views.
A View is a drawable object used as an element in your UI layout, such as a button, image, or (in this case) a text label.
Each of these objects is a subclass of the View class and the subclass that handles text is TextView.


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.main);
        TextView tv = new TextView(this);
        tv.setText("Hello111, Android");
        setContentView(tv);
    }


TextView tv = new TextView(this):
create a TextView with the class constructor, which accepts an Android Context instance as its parameter.
A Context is a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on.
The Activity class inherits from Context, and because your HelloAndroid class is a subclass of Activity, it is also a Context. So, you can pass this as your Context reference to the TextView.

setContentView(tv):
Finally, you pass the TextView to setContentView() in order to display it as the content for the Activity UI. If your Activity doesn't call this method, then no UI is present and the system will display a blank screen.

 

4 Upgrade the UI to an XML Layout

/res/layout/main.xml
 <?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   android:text="@string/hello"/>
/res/values/strings.xml


Instead of passing setContentView() a View object, you give it a reference to the layout resource. The resource is identified as R.layout.main, which is actually a compiled object representation of the layout defined in /res/layout/main.xml.


R.java :
A project's R.java file is an index into all the resources defined in the file. You use this class in your source code as a sort of short-hand way to refer to resources you've included in your project. This is particularly powerful with the code-completion features of IDEs like Eclipse because it lets you quickly and interactively locate the specific reference you're looking for.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值