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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:55:57+00:00 2026-06-16T04:55:57+00:00

Android input validation when a button is pressed and display the validation message in

  • 0

Android input validation when a button is pressed and display the validation message in a dialog as shown below.

Codename is required
Password is required
USername is required.
Enter the valid Email id.

Dismiss

This is my code:

 btninsert = (Button)findViewById(R.id.new_customer);
    btninsert.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            EditText Firstname = (EditText) findViewById(R.id.tf_userName);
            EditText Lastname = (EditText) findViewById(R.id.tf_password);
            EditText Baddress = (EditText) findViewById(R.id.tf_address);
             if(Firstname.getText().toString().length() == 0 )
                Firstname.setError( "Firstname is required!" );
            else if(Lastname.getText().toString().length() == 0 )
                Lastname.setError( "Lastname is required!" );
             else if(Baddress.getText().toString().length() == 0 )
                Baddress.setError( "Address is required!" );
                else
                         insertValues();
                        }
                       });

How can i validate.

  • 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-16T04:55:58+00:00Added an answer on June 16, 2026 at 4:55 am

    Change current code as for input validation on EditText show validation message in a dialog :

    First create a method for showing Alert as:

    public void showAlertbox(String erroMessage){
    AlertDialog alertDialog = new AlertDialog.Builder(
                    YOur_Current_Activity.this).create();
    
          // Setting Dialog Title
       alertDialog.setTitle("Error Message");
    
        // Setting Dialog Message
         alertDialog.setMessage(erroMessage);
    
    
         // Setting OK Button
         alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
                    // Write your code here to execute after dialog closed
    
           }
            });
    
      // Showing Alert Message
     alertDialog.show();
    
    }
    

    Make a method to check validation on String :

    public static boolean notEmpty(String s) {
     return (s != null && s.length() > 0);
    }
    

    call this method on button click as:

    btninsert.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
    
         if(notEmpty(Firstname.getText().toString())){
              if(notEmpty(Lastname.getText().toString())){
                   if(notEmpty(Baddress.getText().toString())){
    
                        // instert here
                        insertValues();
                    }else{
                        showAlertbox("Baddress Name Empty!!"); 
    
                }else{
                  showAlertbox("Lastname Name Empty!!");
                }
           }
         else{
             showAlertbox("First Name Empty!!");
           }
    
       }
    //...your code here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I developed an application in android. Its input fields are working fine e.g. username
There is iOS US2FormValidator library for user input validation (see the picture below). I
Does Android EditText has input type with clear button? It should work like html
I am trying to build an Android input control which allows the user to
I followed these two exemples of developer.android (Creating an Input Method, Soft Keyboard sample).
Recently upgraded my Android SDK install to r20 and now keyboard input seem to
I am implementing input method related application in Android. In this application I'm using
I used android:inputType = phone to take phone number as input, but if i
I am working on an android Application where I am willing to get input
I'm building a custom keyboard in android. My input.xml: <com.mykeyboard.MyKeyboardView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/keyboard android:layout_width=match_parent android:layout_height=wrap_content

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.