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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:18:18+00:00 2026-05-18T08:18:18+00:00

I am using a menu in my application same as this post… I am

  • 0

I am using a menu in my application same as this post… I am using a gallery view for display my menu items.

Text Gallery on Android?

Problem is that, i implement onItemSelected listener for gallery, so that when new item is selected data related to that topic loaded. But i also want to allow user to scroll the gallery fully. But each time when user move to next item onItemSelected() function called and it start loading data.

All i want to do is to put some delay in onItemSelected() function, so that if in between that delay user scroll next item than there is no need to load data of previous but for the current. Time may be 1 second. If user dose not go for next item in 1 second, that data of that item must be loaded.

Can anyone help? I thought to start a thread, but each time for onItemSelected() there will be new thread…

I tried this too

public class TimerThreadForCategoriesMenu extends Thread{

int old = -1;
int cur = -1;
CategoriesActivity catAct = null;

public TimerThreadForCategoriesMenu(CategoriesActivity act , int cu) {
    this.cur = cu;
    old = cu;
    this.catAct = act;

}
@Override
public void run() {
    Looper.prepare();

    do{
        old = this.cur;
        for(int i = 0; i<15; i++){
            try{
                Thread.sleep(100);

            }catch (Exception e) {
                e.printStackTrace();
            }
        }

    }while(cur != old);
    catAct.performTask();
    Looper.loop();  
}

public void setCur (int curr){
    this.cur = curr;
}

}

And in OnItemSelected()

      if(timer == null){  

        timer = new TimerThreadForCategoriesMenu(this, arg2);
        timer.start();
    }
    timer.setCur(curInd);

Found Exception:

11-24 16:48:50.046: ERROR/AndroidRuntime(8049): Uncaught handler: thread Thread-8 exiting due to uncaught exception
11-24 16:48:50.126: ERROR/AndroidRuntime(8049): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
11-24 16:48:50.126: ERROR/AndroidRuntime(8049):     at android.view.ViewRoot.checkThread(ViewRoot.java:2683)
11-24 16:48:50.126: ERROR/AndroidRuntime(8049):     at android.view.ViewRoot.invalidateChild(ViewRoot.java:570)
11-24 16:48:50.126: ERROR/AndroidRuntime(8049):     at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:596)
11-24 16:48:50.126: ERROR/AndroidRuntime(8049):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:2396)
11-24 16:48:50.126: ERROR/AndroidRuntime(8049):     at android.view.View.invalidate(View.java:4945)
11-24 16:48:50.126: ERROR/AndroidRuntime(8049):     at

  • 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-18T08:18:19+00:00Added an answer on May 18, 2026 at 8:18 am

    use a Handler and postDelayed() a Runnable

    Edit:

    It depends on what processing you wish to do.
    Have a look at Looper in the reference. The UI has its own Looper so you don’t need to create one. Just create a Handler, however any Runnable posted to the UI Thread Handler will be run on the UI thread. If you are doing stuff that takes a while to complete, create you’re own Thread with a Handler and post Runnables to that.
    http://developer.android.com/reference/android/os/Looper.html

    Edit:

    So create members in your Activity.

    Handler handler;
    MyLooper mylooper;
    

    Your thread looper.

    class MyLooper extends Thread {
      public Handler handler;
    
      public void run() {
          Looper.prepare();
    
          handler = new Handler() {
              public void handleMessage(Message msg) {}
          };
    
          Looper.loop();
      }
    }
    

    In your Activity.onCreate.

    handler = new Handler();
    mylooper = new MyLooper();
    

    Now create Runnables.

    Runnable processinfo = new Runnable() {
        public void run() {
            //  your processing here
        }
    }
    
    Runnable updateui = new Runnable() {
        public void run() {
            //  update ui component here
        }
    }
    

    Now to get these Runnables to execute.

    mylooper.handler.postDelayed(processinfo, 1000);
    
    handler.post(updateui);
    

    You will need some logic to handle cancelling the Runnable based on the needs of your delay.

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

Sidebar

Related Questions

No related questions found

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.