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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:15:19+00:00 2026-06-08T14:15:19+00:00

I am developing an app in which I would like to display a view

  • 0

I am developing an app in which I would like to display a view when a touch event is registered. The problem is the view will not display and my code become unresponsive.

Here is my view:

public class TouchFX extends View {

RectF oval;
float Tx, Ty;
Paint paint;
int longSide, numRun;
float top, left, right, bottom;
boolean removable;

public TouchFX(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    Tx = TouchService.x;
    Ty = TouchService.y;
    paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setAntiAlias(true);
    paint.setStrokeJoin(Paint.Join.ROUND);
    numRun = 0;
    removable = false;
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);

    if (canvas.getWidth() > canvas.getHeight())
        longSide = canvas.getWidth();
    else
        longSide = canvas.getHeight();

    if (numRun == 0) {
        left = Tx - (longSide / 15);
        top = Ty + (longSide / 15);
        right = Tx + (longSide / 15);
        bottom = Ty - (longSide / 15);
    } else if (numRun <= 8) {
        left += 2;
        top += 2;
        right += 2;
        bottom += 2;
    }
        oval = new RectF(left, top, right, bottom);

    if (numRun < 9)
        canvas.drawArc(oval, 0, 360, false, paint);
    else
        removable = true;

    numRun++;

    try {
        Thread.sleep(400);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
    }
}

Here is my onTouch handler:

public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    if (v == tv && event.getAction() == MotionEvent.ACTION_DOWN
            && isRunning == true) {
        x = event.getX();
        y = event.getY();

        tfx = new TouchFX(this);

        winmngr.addView(tfx, lpFX);


                    //Do some stuff, make some Toasts


        while(!tfx.removable) {
            //waiting for animation to end
        }

        winmngr.removeView(tfx);
    }
    return false;
}

Now, obviously it’s getting stuck within the while loop, but why isn’t it drawing the arc and updating the boolean?

  • 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-08T14:15:20+00:00Added an answer on June 8, 2026 at 2:15 pm

    it is getting stuck because onTouch event operates in UI thread (so as onDraw). So you are blocking your UI thread in while loop and onDraw() doesn’t get processor time.

    Consider using callback mechanism, so removeView() routines is triggered by your onDraw method. Also sleep(400) in UI thread is extremely bad idea. You can try to use handler and do post delayed execution:

     public class YouCustomView extends View
     {
    
         Handler handler = new Handler();
    
         @Override
         protected onDraw(Canvas canvas){
             //your draw routine here
             .... 
    
             //wait 400 ms and remove view
             handler.postDelayed(new Runnable()
             {
                 @Override
                 public void run()
                 {
                     //trigger callback to remove view
                 }
             }, 400);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an app in which i would like to share my data
I'm developing a Rails 3 app deployed on Heroku which would like to optimize.
I'm developing an app which uses APNS and I would like to distribute it
I am developing an iOS app of which my clients would like roughly 50
I'm developing an app in which there's hundreds of different calculations involved and would
I am currently developing an app which will be on Android Market. How can
I'm developing an app which requires the system to get the touch events even
I'm developing an app that would display images and change them according to the
I am developing an app in Xcode on Mac and would like to know
I am developing in Rails an app where I would like to rank a

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.