1

我想设置它,当我选中复选框然后显示AlertDialog. 但是发生了一个问题.. Eclipse 总是在我的AlertDialog.

new AlertDialog.Builder(setting.this)

代码:

private CheckBox.OnCheckedChangeListener chkPasswordListener = new CheckBox.OnCheckedChangeListener(){

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (chkSetPassword.isChecked()){
                new AlertDialog.Builder(setting.this)  //AlertDialog show red line.
                .setMessage("Message,確定要結束?")
                .setPositiveButton("確定", new DialogInterface.OnClickListener() 
                {                   
                    public void onClick(DialogInterface dialoginterface, int i)
            //      public void onClick(DialogInterface dialog, int i)  
            //      TODO Auto-generated method stub                 
                    {
                        finish();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialoginterface, int i)
                    {
            //      public void onClick(DialogInterface dialog, int which) {
            //      TODO Auto-generated method stub

                    }

                })
                .show();
            }
        }

我丢了什么东西吗?请帮我..

4

1 回答 1

0

您应该按以下方式完成代码:

            }

        })
        .show();
    }
  };      // THIS LINE WAS MISSING
}

你应该用 }; 这一行:

 private CheckBox.OnCheckedChangeListener chkPasswordListener
     = new CheckBox.OnCheckedChangeListener(){
于 2013-01-17T07:51:26.640 回答