Note that there are some explanatory texts on larger screens.

plurals
  1. POonActivityResult() not getting executed in DialogFragment
    primarykey
    data
    text
    <p>I have been looking in thousand posts for this, but I do not find how to solve my problem.</p> <p>I have an ImageView. When the user clicks on this ImageView, a DialogFragment is displayed, and the user can choose between taking a new picture with the camera, or selecting a picture from the gallery. Until here everything works fine. </p> <p>The problem is, that the picture selected by the user, should replace the current one in the ImageView, but this bit, is the one that is not working, because the onActivityResult() function that executes this code is not being executed, so the image in the ImageView always remains the same. I would appreciate any help, because I do not see or understand, why this code is not being executed.</p> <p>I am getting a warning in the LogCat right after the user selects the image:</p> <pre><code>05-07 12:17:11.542: I/ActivityManager(59): Displayed activity com.android.gallery/com.android.camera.ImageGallery: 935 ms (total 935 ms) 05-07 12:17:12.812: W/FragmentActivity(3614): Activity result no fragment exists for index: 0x10001 05-07 12:17:12.862: W/InputManagerService(59): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@45fd9c38 (uid=10016 pid=317) </code></pre> <p>Activity.java:</p> <pre><code>private ImageView imageLoader = null; imageLoader = (ImageView) findViewById(R.id.f_imageLoader); imageLoader.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { ImageLoaderDialog imageLoaderDialog = new ImageLoaderDialog(imageLoader); imageLoaderDialog.show(getSupportFragmentManager(), "imageLoaderDialog"); } </code></pre> <p>Activity.xml:</p> <pre><code>&lt;ImageView android:id="@+id/f_imageLoader" android:layout_width="wrap_content" android:layout_height="0dip" android:layout_weight="0.20" android:contentDescription="@string/imgDesc" android:src="@drawable/my_image" /&gt; </code></pre> <p>ImageLoaderDialog.java:</p> <pre><code>//Dialog for choosing between new camera image or gallery image. public class ImageLoaderDialog extends android.support.v4.app.DialogFragment { private ImageView targetImageView = null; final int TAKE_PICTURE = 0; final int PICK_PHOTO = 1; public ImageLoaderDialog (View view) { targetImageView = (ImageView) view; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Selecciona"); final String[] imageSources = getResources().getStringArray(R.array.imageSources); builder.setItems(imageSources, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch(item) { case TAKE_PICTURE: Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(takePicture, TAKE_PICTURE); break; case PICK_PHOTO: Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(pickPhoto, PICK_PHOTO); break; } } }); return builder.create(); } //Set image to user's selected image. public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == android.app.Activity.RESULT_OK) { Uri selectedImage = intent.getData(); Log.i("IMAGEN", ""+selectedImage); targetImageView.setImageURI(selectedImage); } } } </code></pre> <p>Any help would be very appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload