尝试使用对话框按钮从图库和相机中获取图像。无法获得对话框。

时间:2012-02-27 15:37:49

标签: android

这是我从相机和图库中获取图片的代码:

             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 个答案:

答案 0 :(得分:1)

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();
            }
        }
};
  1. 希望这会有助于你设定拳头的持续时间 对话短暂所以它很快就会消失

答案 1 :(得分:1)

尝试,

AlertDialog alert = builder.create();
alert.show(); // did you miss this?