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

  • Home
  • SEARCH
  • 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 8723051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:32:29+00:00 2026-06-13T07:32:29+00:00

I created a Dialog with a TextEdit as a number input to convert it

  • 0

I created a Dialog with a TextEdit as a number input to convert it to a double value.
I want to prevent an exception by checking, if the TextEdit input is empty but it always jumps to the else statement and therefore creates an exception when the EditText is blank.

final Builder builder = new Builder(this);
            final EditText input = new EditText(this);
            input.setKeyListener(DigitsKeyListener.getInstance(false, true));
            builder
                .setTitle(R.string.dialog_title_addmark)
                .setMessage(R.string.dialog_addmark)
                .setView(input)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        if (input.toString().trim().length() == 0) {

                            Toast.makeText(Marks.this, R.string.input_empty, Toast.LENGTH_SHORT).show();

                        } else {
                            Double value = Double.valueOf(input.getText().toString());
                            db.insertMark(selection, value);
                            getData();
                        }
                    }
                })
                .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                    }

                })
                .show();

I also tried it checking
(input.toString() != null)
but that does not work either.

Thanks for your help

  • 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-13T07:32:30+00:00Added an answer on June 13, 2026 at 7:32 am

    If you want the text from a EditText object, you should use the following line of code:

    input.getText().tostring();
    

    where input is a EditText-object.

    Using the code

    input.toString();
    

    will give you a string representation of the object, and as long as the object is not null, the toString of that object will be not null, so using input.toString() != null will not give you any useful information.

    That means that you should do the following validation:

    if (input.getText().toString().trim().length() == 0) to figure out if the input object contains some text.

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

Sidebar

Related Questions

I've created a dialog in dojo with a few input fields. Based upon a
I created a dialog successfully with resize enable but for my project I need
In a long-running operation, I'm showing a popup dialog (created from ProgressDialog to prevent
I've created a dialog where I ask for some lengths of a number of
I have created a dialog. Now what I want is that onClick of the
I want to have a custom dialog (created using layout) in Preferences . What
I have created a dialog box and i want to load a HTML page
I have a custom dialog created and and I want to apply a custom
Hi I want to change the dialog text size.Dynamically I created th dialog, I
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',

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.