Check Mobile App
Read now
Start a Project

Using DialogFragment instead of Basic Dialog

Save

A Dialog is a UI that is displayed in a window of its own. The dialog stays put until the user dismisses it with an action.
Dialogs are used to alert the user to some condition or to simply get the user to make a choice or input some data.

Before Honeycomb version, there was basic Dialog with its own showDialog / dismissDialog methods in Activity.

Honeycomb introduced Fragments to support reusing portions of UI and logic across multiple activities in an app. In parallel, the showDialog / dismissDialog methods in Activity are being deprecated in DialogFragments.
Before proceeding to DialogFragments, let us discuss Fragment:

A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running. It is like a “subactivity” that you can reuse in different activities.
DialogFragments:

As a DialogFragment is also a Fragment that displays a dialog window, floating on top of its activity’s window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment’s state.

Let us create a basic example by taking activity in which we extends DialogFragment instead of normal Fragment:
activity_main.xml

activity_my_dialog_fragment.xml

MainActivity.java

MyDailogFragment.java

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Very good company, we did get app extension for Magento 2 website. The support was very good they help us through the process. Webkul team is very supportive, I would recommend them.

Yasser Mohamed

Yasser Mohamed

Talk to Sales

Global

Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home