Android SDK中覆盖AlertDialog事件 [英] Android SDK override AlertDialog events

查看:115
本文介绍了Android SDK中覆盖AlertDialog事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实例化一个警告对话框,如下所示:

  AlertDialog myAlert =新AlertDialog.Builder(myContext).create();

有没有办法来覆盖此对话框的的onkeydown 事件?


解决方案

  AlertDialog.Builder打造=新AlertDialog.Builder(本);
build.setMessage(这是一个消息,耶。)
.setPositiveButton(Awesomesauce。新OnClickListener()
{
    公共无效的onClick(DialogInterface对话框,INT ID)
    {
        //这里的东西
        dialog.dismiss(); //关闭窗口
    }
};
AlertDialog myAlert = build.create();
myAlert.show();

您还可以添加 .setNegativeButton() .setNeutralButton()来改变中性/负按钮了。

Android的SDK文档,因为这是这里

I am instantiating an alert dialog like so:

AlertDialog myAlert = new AlertDialog.Builder(myContext).create();

Is there a way to override the OnKeyDown event for this dialog?

解决方案

AlertDialog.Builder build=new AlertDialog.Builder(this);
build.setMessage("This is a message, dawg.")
.setPositiveButton("Awesomesauce.", new OnClickListener()
{
    public void onClick(DialogInterface dialog, int id)
    {
        //stuff here
        dialog.dismiss(); //closes the window
    }
};
AlertDialog myAlert=build.create();
myAlert.show();

You can also add a .setNegativeButton() or .setNeutralButton() to change the neutral/negative buttons, too.

The Android SDK doc for it is here.

这篇关于Android SDK中覆盖AlertDialog事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆