Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8444843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:30:06+00:00 2026-06-10T09:30:06+00:00

I am trying to implement a relatively simple DialogFragment that is supposed to contain

  • 0

I am trying to implement a relatively simple DialogFragment that is supposed to contain an image and a OK button and I want to display it on demand from my activity.

I set its layout in onCreateView via inflater.inflate, but I can’t figure out how to tell it that the implementation for the OK button event handler is located in my custom DialogFragment class. It seems to try to find it in the activity, which is not what I want. Would calling getDialog().dismiss() be enough to dismiss it?

Here is how I create a dialog in my activity:

ResponseDialog dialog = new ResponseDialog();
dialog.show(getFragmentManager(), "dialog_response_image");

Also, some folks say that my custom DialogFragment should set getDialog().setCanceledOnTouchOutside(true);, but where should I set this. In onActivityCreated?

How can I get access to its view from the activity, if I wish to set the source of the image contained by it?

Also, for some reason, it fills up the entire display, even if I use static width / height. Does anyone know how to fix this? – I managed to fix this by swithching to LinearLayout instead of RelativeLayout in the DialogFragment layout XML…

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/background_color"
    tools:context=".MainActivity"
    android:layout_width="200dp"
    android:layout_height="400dp"
    android:id="@+id/dialogImageReponse" >

    <Button
        android:id="@+id/dialogButtonOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/ok"
        android:onClick="Ok" />

</RelativeLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:30:08+00:00Added an answer on June 10, 2026 at 9:30 am

    I’ll try to answer each of your questions:

    1.) About the “how to tell it that the implementation for the OK button event handler is located in my custom DialogFragment class” I’m not sure why you want to do that since you haven’t told us.

    2.) “Would calling getDialog().dismiss() be enough to dismiss it?”. If you wish to dismiss the DialogFragment from your Activity then you just need to call dialog.dismiss() (‘dialog’ here refers to ResponseDialog dialog = new ResponseDialog(); so obviously you can only call dialog.dismiss() once you’ve created the ResponseDialog object.

    3.) Regarding “getDialog().setCanceledOnTouchOutside(true);” Once again you just need to call

    dialog.setCanceledOnTouchOutside(true); 
    

    immediately after this:

    ResponseDialog dialog = new ResponseDialog();
    dialog.show(getFragmentManager(), "dialog_response_image");
    

    4.) You can get access to its view by calling:

    View v = dialog.getView();
    

    Although if you just wish to set the source of the image to be used contained by it, and I assume you want to use a photo or a picture stored in your phone then you would have to use a parametrized constructor for ResponseDialog like this and as a parameter you would have to pass the URI OR the filepath of the picture that you would like displayed in the dialogfragment :

    ResponseDialog dialog = new Response(String filepath);
    

    and then in your custom dialog class which I understand is ResponseDialog you would have to use this filepath (received in the constructor) to create a bitmap and then set the bitmap as the source of the ImageView in that DialogFragment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to implement some relatively simple 2D sprite batching in OpenGL ES 2.0
I am trying to implement the (relatively simple) linear homogeneous (DLT) 3D triangulation method
I am trying to implement a very simple little dropdown-style mini-menu that will appear
I'm relatively new to js and I'm trying to implement a simple .animate() feature
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
Based on a college-project I'm trying to realize a relatively simple game (Poker) where
I've been trying to create what I think is a relatively simple layout for
I am trying to implement an admin feature on my site that allows an
I'm trying to implement a custom UISlider (subclass of UISlider), that behaves in a
Im relatively new to iPhone development and Im trying to implement Facebook functions in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.