iphone/android比较学习之──提示框的使用【转】

来自:http://blog.csdn.net/pjk1129/article/details/6619700

一、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.
}
}

UIAletView:

-(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();//如果要显示对话框,一定要加上这句


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值