目前共有5篇帖子。 內容轉換:不轉換▼
 
點擊 回復
307 4
【程序】点击按钮后弹出对话框
一派護法 十九級
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

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:307 回複數:4
評論數: ?
作者: 巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2014-11-22 19:23
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。