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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:22:01+00:00 2026-06-15T17:22:01+00:00

how do i test if the field isn’t filled up by the user? i

  • 0

how do i test if the field isn’t filled up by the user? i want to show a prompt that they have to fill up the fields completely. but this code still accepts even if the name is null and the number is entered.

public void onClick(View arg0)
{
    switch(arg0.getId())
    {
    case R.id.bSQLUpdate:
        boolean diditwork = true;
        try
        {
        String name = sqlName.getText().toString();
        String number = sqlNumber.getText().toString();

        GroupDb entry = new GroupDb(ContactDb.this);
        entry.open();
        if(name != null && number != null)
        {
            if((!entry.hasDuplicateNameNumber(name, number)) )
            {
                entry.createEntry(name, number);

            }
            else
            {
                diditwork = false;
                Dialog d = new Dialog(this);
                d.setTitle("Error");
                TextView tv = new TextView(this);
                tv.setText("Duplicate name or number. Please try again.");
                d.setContentView(tv);
                d.show();
                sqlName.setText("");
                sqlNumber.setText("");
            }
        }
        else
        {
            diditwork = false;
            Dialog d = new Dialog(this);
            d.setTitle("Error");
            TextView tv = new TextView(this);
            tv.setText("Please fill up all fields. Please try again.");
            d.setContentView(tv);
            d.show();
            sqlName.setText("");
            sqlNumber.setText("");
        }

        entry.close();
        }
        catch(Exception e)
        {
            diditwork = false;
            String error = e.toString();
            Dialog d = new Dialog(this);
            d.setTitle("Update failed");
            TextView tv = new TextView(this);
            tv.setText(error);
            d.setContentView(tv);
            d.show();
            sqlName.setText("");
            sqlNumber.setText("");
        }
        finally
        {
            if(diditwork)
            {
                Dialog d = new Dialog(this);
                d.setTitle("Contact list updated");
                TextView tv = new TextView(this);
                tv.setText("Success");
                d.setContentView(tv);
                d.show();
                sqlName.setText("");
                sqlNumber.setText("");
            }
        }
        break;

    case R.id.bSQLOpenView:
        Intent intent = new Intent();
        intent.setClass(ContactDb.this, CustomListView.class);

        startActivityForResult(intent, 0);
        break;

    }

}// end onclick
  • 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-15T17:22:03+00:00Added an answer on June 15, 2026 at 5:22 pm

    You tested your string with null.When text box is empty String name is not null, it is an empty string.So compare it like below

    if(!name.trim().equals("") && !number.trim().equals("")){
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field that isn't required but I still want to add a
I want to get the text field test out of this web page. How
I need a script that will test an input field's contents to see if
In a table 'test' I have an integer field TestID, with an index. SELECT
I have the following array of structures called test, where each field is a
I have an immutable class with some private fields that are set during the
Sorry if that description isn't clear...wasn't sure how else to put it. I have
Let's say I have an HTML page with a text field that ask the
I have an asp.net web app that's going through a pen test by internal
I want to test for an intersection of a ray with a voxel field.

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.