目前共有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許可協議進行許可。