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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:55:20+00:00 2026-06-03T12:55:20+00:00

I have a search function when the user types something in an input and

  • 0

I have a search function when the user types something in an input and presses enter, an asynctask will fire off to retrieve the results. I want my textview (visibility=gone) which says “Loading” to be displayed before/while the asynctask is running. However, it only displays the loading text for a second, before showing the results in postExecute. So during the few seconds the asynctask is running, I do not see a loading text. Does anyone know why?

As you can see in my code, I have set the loading text to be visible before the asynctask runs and during preExecute in the asynctask, and neither solves the problem.

edit is my EditText, retrieving is my “loading” TextView

Here is my EditText keylistener:

edit.setOnKeyListener(new OnKeyListener() {

            public boolean onKey(View v, int keyCode, KeyEvent event) {

                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    switch (keyCode) {
                    case KeyEvent.KEYCODE_ENTER:
                        retrieving.setVisibility(View.VISIBLE);

                        SearchTask task = (SearchTask) new SearchTask(edit,retrieving);
                        task.execute(edit.getText().toString());

                        try {
                            task.get();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } catch (ExecutionException e) {
                            e.printStackTrace();
                        }

                        break;
                    }
                }
                return false;
            }
        });

Here is the asynctask:

public class SearchTask extends AsyncTask {

private EditText edit;
private TextView retrieving;

public SearchTask(EditText edit,TextView retreiving, ) {
    this.edit = edit;
    this.retrieving = retreiving;
}

@Override
protected void onPreExecute() {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
    retrieving.setVisibility(View.VISIBLE);
}

@Override
protected Playlist doInBackground(String... params) {

   //download and parse xml
}

@Override
protected void onPostExecute(Playlist playlist) {

    retrieving.setVisibility(View.GONE);

}
  • 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-03T12:55:21+00:00Added an answer on June 3, 2026 at 12:55 pm

    OK I read your code further and I see the problem. Your task.get() command is locking up your UI. Therefore your onPreExecute never has a change to run, before getting blocked by task.get().

    You should elminate that block of code entirely and do anything that needs to be done in the onPostExecute() method of your async task.

    For example:

    @Override
    protected void onPostExecute(Playlist playlist) {
    
        retrieving.setVisibility(View.GONE);
        // do something with playist here. Play store it, etc...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a binary search function that will search for a word in an
How can i have slide downeffect? The effect will be similar with search function
I have an interface where a user will enter the name of a company.
I have a search function in which i am returning all the records of
I have an active directory search function: Function GetAdInfo(ByVal ADDN As String, ByVal ADCommonName
hai I have a magento web site. In this the search function compare with
I have an array returned by the function Search.all : => [#<Search id: 7,
I have a similar code snippet like this class Search { public function search($for,
I am attempting to create a search function for user profiles on my site.
I have a application which allows user to make a search. Based on the

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.