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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:20:13+00:00 2026-06-09T13:20:13+00:00

Got a few problem here. I have created a arrays of EditText and it

  • 0

Got a few problem here. I have created a arrays of EditText and it is working fine. Now I am getting an error when one of the EditText is empty.
Here is my code:

int[] textIDs = new int[] {R.id.etFirstName, R.id.etLastName, R.id.etEmail, R.id.etAddress, R.id.etCity, R.id.etRegion, R.id.etMobile, R.id.etLandLine, R.id.etYear, R.id.etMonth, R.id.etDay };
        for(int j=0; j<textIDs.length; j++) {
            EditText editText = (EditText) findViewById(textIDs[j]);
            if(editText.getText().toString().trim().equals(""))
            {
                 // editText is empty
                Toast.makeText(MainActivity.this, "Request cannot performed..\n Please ensure all fields are filled", Toast.LENGTH_SHORT).show();
                break;
            } 
            else 
            {
                 // editText is not empty
                Toast.makeText(MainActivity.this, "12", Toast.LENGTH_SHORT).show();
            }

The main problem using this code is that the loop continues to do its function that this code
Toast.makeText(MainActivity.this, "12", Toast.LENGTH_SHORT).show();
continues to show in every loop. Is there any way that this Toast shows after the looping is done?

  • 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-09T13:20:14+00:00Added an answer on June 9, 2026 at 1:20 pm
        boolean doShowToast = false;
        int[] textIDs = new int[] {R.id.etFirstName, R.id.etLastName, R.id.etEmail, R.id.etAddress, R.id.etCity, R.id.etRegion, R.id.etMobile, R.id.etLandLine, R.id.etYear, R.id.etMonth, R.id.etDay };
        for(int j=0; j<textIDs.length; j++) {
            EditText editText = (EditText) findViewById(textIDs[j]);
            if(editText.getText().toString().trim().equals(""))
            {// editText is empty
                Toast.makeText(MainActivity.this, "Request cannot performed..\n Please ensure all fields are filled", Toast.LENGTH_SHORT).show();
                break;
            } 
            else 
            {
                 // editText is not empty
                doShowToast = true;
            }
        }
        if(doShowToast){
             Toast.makeText(MainActivity.this, "12", Toast.LENGTH_SHORT).show();
        }
    

    by using a boolean you will only show the toast for the else statement once, after the loop has exited, and only if the else statement was called, so only if “editText is not empty”

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

Sidebar

Related Questions

Got an annoying problem here. I've got an NHibernate/Forms application I'm working through SVN.
I got an interesting problem: file1.csv has a few hundred rows like: Code,DTime 1,2010-12-26
I have probem / strange question, i got algorithm with few for loops and
i have form in drupal which uploads images and has got few checkboxes in
So I have googled whole day, got few answers how to do this, and
I have got a few tables which I am trying to join. I just
I've got a few controllers here at work that contain methods I can use
I am fairly new to Matlab and have a few questions. I got two
I can't figure out what's happening here. I've got a few lists set up,
Ok, so here's my current setup and my problem at the moment. I have

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.