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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:15:03+00:00 2026-06-18T10:15:03+00:00

I have a custom View class which is drawing images. The problem is that

  • 0

I have a custom View class which is drawing images. The problem is that when I use Thread.sleep(200); in the onDraw method, it also affects the XML elements that are in the same activity. So I have to wait 200 miliseconds untill something happens.

MainPage extends Activity implements OnClickListener{
    onCreate(...){

        RelativeLayout rl = (RelativeLayout) findViewById(R.id.main_rl);
        rl.addView(new CustomView(this));
    }

    onClick(View v){
        switch(v.getId){
            ...
        };
    }
}


CustomView extends View{

    onDraw(){
        try{
            Thread.sleep(200);
            ....
        }
    }
}

Any help will be appreciated.

  • 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-18T10:15:05+00:00Added an answer on June 18, 2026 at 10:15 am

    Never run long operations in any UI listener callback (or anywhere else that runs on the UI thread) in Android. Instead, create a new thread to perform the sleep and then do whatever needs to be done. Just remember that if you want to interact with the UI again, you need to do that within the UI thread, which you can schedule by calling runOnUiThread().

    CustomView extends View{
    
        onDraw(){
            (new Thread(myRunnable)).start();
        }
    }
    
    Runnable myRunnable = new Runnable() {
        void run() {
            try { Thread.sleep(...); } catch...;
            do_non_ui_things_if_needed();
            runOnUiThread(some_runnable_for_this_if_needed);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a custom view class which is drawing a 2d game board
I need to have a class which extends view that overrides the onSizeChanged method
I have a custom-made view that extends the View class. I would like 2
I have a custom view, that has page and block. But the problem when
I am creating a custom view which will have a bitmap so that user
I have a created custom table view cell class named CustomCell which inherits from
I have a custom model class which contains a decimal member and a view
I have a custom View class that extends Spinner. I'm trying to figure out
I have a custom view which is extending View : public class MyView extends
I have a class that subclasses UIView called DrawView. This class contains custom drawing

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.