iphone/android比较学习之──提示框的使用
来源:互联网 发布:java awt源码 编辑:程序博客网 时间:2024/04/29 08:37
一、iPhone中的UIActionSheet与UIAlterView
首先,在.h文件中添加Protocol,(Protocol相当于Java中的interface)
@interfaceActionSheetViewController : UIViewController
<UIActionSheetDelegate>
{
...
...
}
-(IBAction)showActionSheetButtonPressed:(id) sender;
-(IBAction)showAlterViewButtonPressed:(id) sender;
在.m文件中实现showActionSheetButtonPressed 方法。
-(IBAction)showActionSheetButtonPressed:(id) sender
{
UIActionSheet*actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Title"
delegate:self
cancelButtonTitle:@"Cancel!"
destructiveButtonTitle:@"OK!"
otherButtonTitles:nil];
[actionSheetshowInView:self.view];//参数指显示UIActionSheet的parent。
[actionSheetrelease];
}
一个IUActionSheet在用户点击Button的时调用,但是当用户选择了destructiveButton或者cancelButton后,如何处理想对应的事件呢?
在UIActionSheetDelegate中,有一个方法,
-(void)actionSheet :(UIActionSheet *) actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
我们需要实现这个方法就可以了。
-(void)actionSheet :(UIActionSheet *) actionSheetdidDismissWithButtonIndex:(NSInteger) buttonIndex
{
//当用户按下cancel按钮
if(buttonIndex == [actionSheet cancelButtonIndex])
{
//DoSomething here.
}
//当用户按下OK按钮
if(buttonIndex == [actionSheet destructiveButtonIndex])
{
//DoSomething here.
}
}
UIAlertView:
-(IBAction)showAlterViewButtonPressed:(id) sender
{
UIAlertView*alertView = [[UIAlertView alloc]
initWithTitle:@"AlertTitle"
message:@"AlterMessage Content"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertViewshow];
[alertViewrelease];
}
UIAlterView相对于UIActionSheet简单,以为它只是一个提示用户的View而已。可以在 UIActionSheet的的处理事件 -(void) actionSheet ...中来调用UIAlterView.
二、Android Dialog用法总结
Android,Dialog, 用法
1、AlertDialog.Builder
Android中的alertDialog的创建一般是通过其内嵌类AlertDialog.Builder来实现的。所以首先浏览一下这个builder所提供的方法:
setTitle():给对话框设置title.
setIcon():给对话框设置图标。
setMessage():设置对话框的提示信息
setItems():设置对话框要显示的一个list,一般用于要显示几个命令时
setSingleChoiceItems():设置对话框显示一个单选的List
setMultiChoiceItems():用来设置对话框显示一系列的复选框。
setPositiveButton():给对话框添加”Yes”按钮。
setNegativeButton():给对话框添加”No”按钮。
2、常见对话框:
在了解完这几个常用的方法之后,看一个小例子,创建一个用来提示的对话框:
Dialogdialog = new AlertDialog.Builder(AlertDialogSamples.this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle(“title”)
.setMessage(“这里是提示信息语句”)
.setPositiveButton(“Ok”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
/* User clicked OK so do some stuff */
}
})
.setNeutralButton(“Cancel”, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
/* User clicked Something so do some stuff */
}
})
.setNegativeButton(R.string.alert_dialog_cancel,newDialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
/* User clicked Cancel so do some stuff */
}
})
.create();
dialog.show();//如果要显示对话框,一定要加上这句
- iphone/android比较学习之──提示框的使用
- iphone/android比较学习之──图片、文件、字符串
- iphone/android比较学习之──获取屏幕分辨率
- iphone 提示(弹出)框的使用
- android学习:自动提示AutoCompleteTextView的使用
- Android学习笔记二十八之AlertDialog提示对话框和几个常用的提示框
- Android学习笔记二十八之AlertDialog提示对话框和几个常用的提示框
- 我的iphone开发学习笔记(五): 使用UIAlertView、声音播放来提示警告
- IPhone之NSBundle的使用
- IPhone之NSFileManager的使用
- IPhone之NSFileManager的使用
- IPhone之NSXMLParser的使用
- IPhone之NSXMLParser的使用
- IPhone之NSFileManager的使用
- IPhone之NSBundle的使用
- IPhone之NSXMLParser的使用
- IPhone之NSXMLParser的使用
- IPhone之NSXMLParser的使用
- Struts logic标签
- IOS开发基础之──双缓冲的实现
- 如何在RSA中导入jar包形式的许可证文件
- android edittext插入表情(基于socket方式)
- ActionMapping总结
- iphone/android比较学习之──提示框的使用
- 线程的同步控制
- 获取datagridview中checkbox选中的多行数据
- Linux git 安装
- 我们需要什么样的“技术”
- X.509 数字证书结构和实例
- 关于当前的经济 写在2011-07-20
- java网络编程:获取某个网址的html内容
- javascript学习笔记