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 8744439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:50:27+00:00 2026-06-13T11:50:27+00:00

I subclass DialogFragment to show an input field to the user. If the user

  • 0

I subclass DialogFragment to show an input field to the user.

If the user does not provide any input I want to keep the dialog open and show an error on the input field. The dialog is dismissed automatically when the user press the positive “Save” button no matter if the input field is empty or not.

How can I override this default behaviour?

code snippet (full code is very long, but you get the idea):

public class SurveySingleQuestionDialog extends DialogFragment implements DialogInterface.OnClickListener {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    return (builder.setTitle(mArgs.getString("question_body"))
            .setView(layout)
            .setPositiveButton(R.string.save, this)
            .setNegativeButton(android.R.string.cancel, null)
            .setCancelable(false)
            .show());

}

@Override
public void onClick(DialogInterface dialog, int which) {

if(validInputs()){

//dismiss dialog and save inputs

}
else{

//show error on input field

}

}

}

Any suggestion?

  • 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-13T11:50:28+00:00Added an answer on June 13, 2026 at 11:50 am

    I think the setNegative / setPositive buttons are designed to dismiss the dialogue after the callback has returned. You would probably be better including your own buttons in your view and dismissing the dialogue yourself

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

Sidebar

Related Questions

I have a subclass and I want it to not include a class attribute
If subclass in objective-c wants to override a super class's method, does it have
Is it possible to subclass dynamically? I know there's ____bases____ but I don't want
I have a subclass based on UIView and i want to change the tint
My CCSprite subclass has two float properties called, velX and velY to keep track
I made of subclass of UIView called Bubble using which i want to draw
I have a UIView subclass that I assign to a text field as follows:
I've subclass Application to keep a global state in static variables. But if the
I've created a subclass of UIImage (UIImageExtra) as I want to include extra properties
I have a subclass of JPanel , and I want it to, as soon

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.