问题描述
- 使用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(); } } });
但是没有运行成功。我也没有看到一个对话框。
请大家指点一二,谢谢!
解决方案
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();
}
}
};
解决方案二:
试一下
AlertDialog alert = builder.create();
alert.show(); // 你好像没添加这个
时间: 2024-12-21 00:46:40