AndroidWidget控件开发教程-2
2012-07-14 09:05
323 查看
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的生命周期
不难看出,其实这些方法都是两两对应的,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”
一、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生命周期中的各个阶段简介 | ||
onCreate() | Calledwhen the activity is first created. | 在Activity第一次创建的时候被调用 |
onStart() | Calledwhen the activity is becoming visible to the user. | 当Activity变得对用户可见的时候被调用 |
onResume() | Calledwhen the activity will start interacting with the user. | 当Activity开始与用户交互的时候被调用 |
onPause() | Calledwhen the system is about to start resuming a previous activity. | 当系统将要开始创建另一个Activity的时候被调用 |
onStop() | Calledwhen the activity is no longer visible to the user, becauseanother activity has been resumed and is covering this one. | 当当前的Activity变得不可见的时候被调用 |
onDestroy() | Thefinal call you receive before your activity is destroyed. | 在你的Activity被销毁之前被调用 两种情况1、系统资源不够 2、调用了activity的finish()方法 |
onRestart() | Calledafter your activity has been stopped, prior to it being startedagain. | 没有被destroy的情况下,再次启动被调用 |
Task与activity之间的关系
入栈与出战
对话框形式的activity的编写:
在androidmanifest
中添加
Android:theme= “@android:style/Theme.Dialog”
相关文章推荐
- asp.net 2.0下一个标准GRIDVIEW功能的实现(不用datasource控件)-.NET教程,Asp.Net开发
- HTML5 Web app开发工具Kendo UI Web教程:Grid网格控件的使用
- ASP.NET 2.0 控件开发速成教程:生成复合控件
- 【VS开发】免费打工仔:一个完善的ActiveX Web控件教程
- DuiVision开发教程(9)-动态创建控件
- iOS 9应用开发教程之使用开关滑块控件以及滚动部署视图
- iOS 9应用开发教程之使用开关滑块控件以及滚动部署视图
- DuiVision开发教程(14)-DUI控件基础类
- mos开发系列教程八:页面代码研究-地图控件页面结构
- 为.net中的ListBox控件添加双击事件-.NET教程,组件控件开发
- Delphi组件开发教程指南(6)实现一个模拟动画显示控件
- Cocos2d-x开发教程 第六节 UI控件(Label)
- Delphi 组件开发教程指南(7)继续模拟动画显示控件
- ArcGIS Server开发教程系列(8)ArcGIS API for Javascript-控件(小部件)
- ASP.NET 控件开发速成教程:生成复合控件
- 在.net应用程序中使用用户控件-.NET教程,组件控件开发(转载)
- surface开发教程[ScatterView控件] 二.
- ArcGIS Server开发教程系列(8)ArcGIS API for Javascript-控件(小部件)(续)纯代码
- Android开发教程:Android常见的十个高级控件