作者共發了5篇帖子。
【程序】点击按钮后弹出对话框
1樓 巨大八爪鱼 2014-11-22 18:25
OnClickListener btn2_events = new OnClickListener() {
            @Override
            public void onClick(View v)
            {
                //Here you must use "MainActivity.this" for the parameter Context.
                //You can not use "getApplicationContext()" any more!
                Dialog dlg = new AlertDialog.Builder(MainActivity.this)
                                .setTitle("A question")
                                .setMessage("How many people are there in your home?")
                                .setPositiveButton("Four", null)
                                .setNegativeButton("Three", null)
                                .create();
                dlg.show();
            }
        };
        findViewById(R.id.button2).setOnClickListener(btn2_events);
2樓 巨大八爪鱼 2014-11-22 18:26
在界面中创建button2后就可以看到效果
4樓 巨大八爪鱼 2014-11-22 19:03
.setPositiveButton("Four", null)
第二个参数可以设置点击按钮后的事件,
一般是new OnClickListener() {},里面一些事件比如onClick,这个和button2那个差不多
5樓 巨大八爪鱼 2014-11-22 19:05
.setPositiveButton("确定", new DialogInterface.OnClickListener() { 
                     
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        // TODO Auto-generated method stub  
                    } 
                })
6樓 巨大八爪鱼 2014-11-22 19:23
回复:5楼
OnClickListener变成了DialogInterface.OnClickListener
View v变成了DialogInterface dialog, int which

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
 
 
©2010-2025 Arslanbar [手機版] [桌面版]
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。