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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:36:11+00:00 2026-06-05T20:36:11+00:00

What is the best practice for checking in an EditText for any values before

  • 0

What is the best practice for checking in an EditText for any values before my onclick from a button is fired off. When its fired off now with no value it errors out and crashes. I tried to do a if(edittext != null){then my onlcick code} and it still crashed when I clicked it after no value in the edittext.

  • 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-05T20:36:13+00:00Added an answer on June 5, 2026 at 8:36 pm

    The reason why if (edittext != null) {...} does not work is because this statement will check for a condition on the actual EditText object, and not its contents.

    If you’re after the contents, simply call edittext.getText() and apply your validation logic to that. There’s a convenience method in TextUtils that you can use to check whether the text is null or empty (""): TextUtils.isEmpty(edittext.getText()). You can use it for plain Java strings too, e.g.

    TextUtils.isEmpty(edittext.getText().toString().trim())
    

    Which will trim leading and trailing spaces first, before the test. Depending on your requirements, you can extend this easily with a regular expression to strip out any white space character etc. As a general tip: search around for “android form validation” and I’m sure you’ll find more pointers.

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

Sidebar

Related Questions

Just checking if there's any best practice when writing a Windows Service. The Service
What do you think is the best practice for checking in code from multiple
What is the best practice for generating valid XML with PHP from user submitted
I'm curious. What is the best practice to auto switch the user from http://www.example.com
Which is more efficient for the compiler and the best practice for checking whether
What's the best practice to handle errors if using objects? A) Before the method
Whats the best practice for getting a commenter's email address from the cookie (this
Best practice is to use unique ivs, but what is unique? Is it unique
Short best practice question: If an object A is injected into another object B,
The 'best practice' (as I see it) to atomically create a new file, is

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.