AndroidWidget控件开发教程-2
一、EditText编辑框的基础知识
由于EditText是由TextView类继承而来的,所以TextView类的方法它都有,这里我们要注意几个特殊的地方:
EditablegetText();返回编辑框内的内容,相当于MFC中的UpdateData(TRUE)
voidsetText();参数是字符串类型或者String类型,设置编辑框内的内容
【注】java中String与int之间的相互转换
String转换为int:
Intn = Integer.parseInt(String a);
Int转换为String:
这里我们有三个方法:
Stringstr = int n + “”;//直接加上一个空字符串
Stringstr = Integer.toString(int n);
Stringstr = String.valueOf(int n);
二、Menu的基础知识
1、在应用程序中添加Menu菜单选项
这需要重载booleanonCreatOptionMenu(Menu menu){}函数
并且在里面添加:
menu.add(int,int,int,intid);
//androiddeveloper中对其的简单解释:
abstract MenuItem add(intgroupId, int itemId, int order, int titleRes)
Variationon add(int,int, int, CharSequence) thattakes a string resource identifier instead of the string itself.
2、为菜单中的Item选项添加响应点击的事件:
这需要重载booleanonOptionsItemSelected(MenuItem item){}
Item.getItemId()== int{};
三、Activity的生命周期
Android Activity生命周期中的各个阶段简介 | ||
Calledwhen the activity is first created. | 在Activity第一次创建的时候被调用 | |
Calledwhen the activity is becoming visible to the user. | 当Activity变得对用户可见的时候被调用 | |
Calledwhen the activity will start interacting with the user. | 当Activity开始与用户交互的时候被调用 | |
Calledwhen the system is about to start resuming a previous activity. | 当系统将要开始创建另一个Activity的时候被调用 | |
Calledwhen the activity is no longer visible to the user, becauseanother activity has been resumed and is covering this one. | 当当前的Activity变得不可见的时候被调用 | |
Thefinal call you receive before your activity is destroyed. | 在你的Activity被销毁之前被调用 两种情况1、系统资源不够 2、调用了activity的finish()方法 | |
Calledafter your activity has been stopped, prior to it being startedagain. | 没有被destroy的情况下,再次启动被调用 |
不难看出,其实这些方法都是两两对应的,onCreate创建与onDestroy销毁;onStart可见与onStop不可见;onResume可编辑(即焦点)与onPause;这6个方法是相对应的,那么就只剩下一个onRestart方法了,这个方法在什么时候调用呢?答案就是:在Activity被onStop后,但是没有被onDestroy,在再次启动此Activity时就调用onRestart(而不再调用onCreate)方法;如果被onDestroy了,则是调用onCreate方法。
Task与activity之间的关系
入栈与出战
对话框形式的activity的编写:
在androidmanifest
Android:theme= “@android:style/Theme.Dialog”