这是我从相机和图库中获取图片的代码:
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();
}
}
});
但是,它不起作用。我也没有看到对话框。
答案 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)
尝试,
AlertDialog alert = builder.create();
alert.show(); // did you miss this?