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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:11:48+00:00 2026-06-02T00:11:48+00:00

I have a view to create an account. If the save button is clicked

  • 0

I have a view to create an account. If the save button is clicked and any of the fields are left open, it displays a toast. If all fields are filled in, the account is saved. I tried to accomplish this with an onClickListener that has an iteration through all the fields. It works perfectly if a field is not filled in and it works perfectly if alle fields are filled, but when a field isn’t filled, I type something in there, try to save again and the button doesn’t do anything.

I think it has something to do with the return, but I don’t know what to do else. If the return wouldn’t be there, I would get a toast for each field that isn’t filled in.

Here’s the relevant code:

private void registerButtonListeners() {
    mCRUDAccountButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for (int i = 0; i < mEditTexts.length; i++) {       
                if(mEditTexts[i].getText().length() == 0){
                    CommonCode.showToast(mNoTextTitles[i], mContext, mViewGroup);
                    mEmptyField = 1;
                    return;
                }
            };
            if (mEmptyField == 0){
                saveState();
            }
        }
    });
}

thanks guys!

  • 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-02T00:11:49+00:00Added an answer on June 2, 2026 at 12:11 am

    You’re never resetting your flag back to 0!

    so…

    @Override
            public void onClick(View v) {
                mEmptyField = 0;//RIGHT HERE (give them the benefit of the doubt)
                for (int i = 0; i < mEditTexts.length; i++) {       
                    if(mEditTexts[i].getText().length() == 0){
                        CommonCode.showToast(mNoTextTitles[i], mContext, mViewGroup);
                        mEmptyField = 1; //You were too optimistic, they failed.
                        return;
                    }
                };
                if (mEmptyField == 0){
                    saveState();
                }
            }
        });
    

    Now, you’re doing this test for the first time, every time. Otherwise, you go through and set that flag to 1, and next time, even though your loop never finds a match, when you get to the if mPentyField == 0 test, it fails cause you set that to 1 in the previous go around.

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

Sidebar

Related Questions

I have a list of action (Create a free account, view stats, etc.). Here
I have a problem with the Create View in the SimpleRepository example in Subsonic
How can I create View on Linked Server db. For Example I have a
If i have a controller action Create that returns a view with the following
I have the following code to create my window, my view and my sub
Im create this code to store page view in database, but i have problem
In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have this view: new.html.haml %h1 New account - form_for @user do |f| =
I have two apps, account and myapp. I'm trying to display in a view

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.