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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:20:42+00:00 2026-05-15T18:20:42+00:00

I am doing a login Activity which basically has an EditText and two Buttons

  • 0

I am doing a login Activity which basically has an EditText and two Buttons.
It looks like this:

http://img249.imageshack.us/img249/9108/loginm.png http://img249.imageshack.us/img249/9108/loginm.png

The EditText has a TextWatcher that validates the user with an AsyncTask that hits a webservice.

The code:

public class Login extends Activity {

    private EditText mUserNameET;
    private Drawable mCorrect;
    private Drawable mIncorrect;
    private ProgressBar mProgressBar;
    private MyApp mApp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        mApp = (MyApp) getApplication();
        mUserNameET = (EditText) findViewById(R.id.user_name_et);
        mUserNameET.addTextChangedListener(new LoginValidator());

        mCorrect = getResources().getDrawable(R.drawable.correct);
        mIncorrect = getResources().getDrawable(R.drawable.incorrect);
        mProgressBar = new ProgressBar(this);
    }

    private class LoginValidator implements TextWatcher {

        private ValidateUserAsyncTask validator = new ValidateUserAsyncTask();

        @Override
        public void afterTextChanged(Editable s) {

            String value = s.toString();

            if ( value.length() == 0 )
                return;

            /* If it's running, cancel it. */
            /* Issue #2 */
            if ( AsyncTask.Status.RUNNING == validator.getStatus() ) {
                validator.cancel(true);
                validator = new ValidateUserAsyncTask();
            } else if ( AsyncTask.Status.FINISHED == validator.getStatus() ) {
                validator = new ValidateUserAsyncTask();
            }

            validator.execute(value);
            /* Issue #1 */
            mUserNameET.setCompoundDrawables(null, null, mProgressBar.getProgressDrawable(), null);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
        }
    }

    class ValidateUserAsyncTask extends AsyncTask<String, Void, Boolean> {

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);

            if ( result ) {
                mUserNameET.setCompoundDrawablesWithIntrinsicBounds(null, null, mCorrect, null);
            } else {
                mUserNameET.setCompoundDrawablesWithIntrinsicBounds(null, null, mIncorrect, null);
            }
        }

        @Override
        protected Boolean doInBackground(String... params) {
            return mApp.validateUser(params[0]);
        }
    }
}

My issues:

While the AsyncTask is working I want to show a ProgressBar inside the EditText.
I tried to do it using:

mUserNameET.setCompoundDrawables(null, null, mProgressBar.getProgressDrawable(), null);

but it doesn’t work.

And I am also a bit worried about creating new instances of the AsyncTask. Am I leaking memory?

  • 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-05-15T18:20:43+00:00Added an answer on May 15, 2026 at 6:20 pm

    While the AsyncTask is working I want
    to show a ProgressBar inside the
    EditText

    Try creating an AnimationDrawable representing your progress indicator, and use that with setCompoundDrawables().

    And I am also a bit worried about
    creating new instances of the
    AsyncTask. Am I leaking memory?

    Well, you can’t reuse AsyncTask instances — they are one-and-done. Bear in mind that AsyncTask uses a thread pool, and so you may have multiple AsyncTasks executing at one time, which may or may not be what you have in mind. I would consider waiting until there has been no typing for, say, 1 second, before doing the Web service stuff.

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

Sidebar

Ask A Question

Stats

  • Questions 485k
  • Answers 485k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer MySQL doesn't have recursive functionality, so you're left with using… May 16, 2026 at 7:45 am
  • Editorial Team
    Editorial Team added an answer In XPath 1.0: /Message/Customers/Customer[not(@pin=/Message/Addresses/Address/@pin1)] May 16, 2026 at 7:45 am
  • Editorial Team
    Editorial Team added an answer Something like this?? Devexpress Winforms Skinning Library Telerik Winforms RadControls… May 16, 2026 at 7:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.