2 xiaoyan 12 xiaoyan_12 于 2013.01.24 18:01 提问

使用Dialog button从gallery和Camer里获取图像,不能得到dialog

我使用的下面代码从 gallery 和 Camerra 获取图像

  upload.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
          AlertDialog.Builder builder = new AlertDialog.Builder(CreatePod.this);
            builder.setMessage("Select") .setCancelable(false).setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
                        gallIntent.setType("image/*"); 
                        startActivityForResult(gallIntent, 10);
                   }
            })
            .setNegativeButton("Camera", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                       startActivityForResult(cameraIntent, 0);
                   }
               });
        AlertDialog alert = builder.create();

            if (bitmap == null) {
                Toast.makeText(getApplicationContext(),
                        "Please select image", Toast.LENGTH_SHORT).show();
            } else {
                dialog = ProgressDialog.show(CreatePod.this, "Uploading",
                        "Please wait...", true);
                //new ImageUploadTask().execute();
            }
        }
    });

但是没有运行成功。我也没有看到一个对话框。
请大家指点一二,谢谢!

2个回答

myq_26
myq_26   2013.01.28 10:32
已采纳
private OnClickListener clicklistener = new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (bitmap == null) {
                Toast.makeText(getApplicationContext(),
                        "Please select image", Toast.LENGTH_LONG).show();
            } else {
                Dialog dialog = ProgressDialog.show(getApplicationContext(), "Uploading",
                        "Please wait...", true);
                //new ImageUploadTask().execute();
            }
        }
};
curie_87
curie_87   2013.01.25 10:33

试一下

AlertDialog alert = builder.create();
alert.show(); // 你好像没添加这个
Csdn user default icon
上传中...
上传图片
插入图片