Ich bin ein Uri von einer Aktivität (über startActivityForResult) abrufen und ich möchte es in einem Dialogfeld anzeigen, aber ich kann es nicht zum arbeiten, ich bekomme eine NullPointerException für das ImageView wenn Ich versuche seinen URI einzustellen.Android AlertDialog mit Bild innerhalb
Hier ist, was ich versucht zu tun:
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
final Uri imageUri = imageReturnedIntent.getData();
AlertDialog.Builder adb = new AlertDialog.Builder(this);
LayoutInflater inflater = LayoutInflater.from(this);
final View view = inflater.inflate(R.layout.image_dialog, null);
adb
.setTitle("Confirm picture?")
.setView(view)
.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
uploadDocument(imageUri);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});
AlertDialog dialog = adb.create();
// This fails:
((ImageView) dialog.findViewById(R.id.dialog_imageview)).setImageURI(imageUri);
dialog.show();
}
Hier ist das Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/dialog_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Habe ich etwas verpasst?
EDIT:
Ich versuchte auch direkt von der Absicht, die Bitmap abzurufen, wie im Android doc angegeben (https://developer.android.com/training/camera/photobasics.html):
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
aber ich habe das Samre Ergebnis (leer/Leerzeichen) .
versucht, das schon, es nicht funktioniert, ich habe nur einen leeren (weiß) Raum anstelle des Bildes: https://t58i.imgup.net/Screenshot3b5f.png –