我向Camera2Fragement类添加了一个新图像,以在警告对话框中显示位图图像,但我只得到没有任何图像的空对话框。我究竟做错了什么。它与我们无法将图像上传到图像视图或其他问题的片段有关。这是我的代码:
public void onClick(View view) {
switch (view.getId()) {
case R.id.picture: {
takePicture();
break;
}
case R.id.info: {
Activity activity = getActivity();
if (null != activity) {
new AlertDialog.Builder(activity)
.setMessage(R.string.intro_message)
.setPositiveButton(android.R.string.ok, null)
.show();
}
break;
}
case R.id.result: { // added code
Activity activity = getActivity();
if (null != activity) {
view = View.inflate(activity, R.layout.dialog_layout, null);
ImageView imgRefInflated = (ImageView) view.findViewById(R.id.dialog_imageview);
Picasso.with(activity).load("/mnt/sdcard/DCIM/mResultImg.jpg").into(imgRefInflated);
//imgRefInflated.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/DCIM/mResultImg.jpg"));
Log.d(TAG, "I can reach here");
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.setView(view);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.show();
}
break;
}
}
}
答案 0 :(得分:0)
您正尝试将图像设置为AlertDialog内部的ImageView,但未显示。像这样重新安排你的代码:
view = View.inflate(activity, R.layout.dialog_layout, activity);
AlertDialog dialog = new AlertDialog.Builder(this)
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setView(view)
.create();
dialog.show();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
ImageView imgRefInflated = (ImageView) view.findViewById(R.id.dialog_imageview);
Picasso.with(activity).load("/mnt/sdcard/DCIM/mResultImg.jpg").into(imgRefInflated);