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

  • Home
  • SEARCH
  • 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 8748549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:32:39+00:00 2026-06-13T12:32:39+00:00

my code is: public class EventDialog2 extends Dialog implements OnTouchListener{ TextView textv; Context con;

  • 0

my code is:

public class EventDialog2 extends Dialog implements OnTouchListener{

    TextView textv;
    Context con;
    Thread t;
    int flag=0;
    public EventDialog2(Context context, int dialogslideanim) {
        super(context, dialogslideanim);
        con = context;

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog2);
        getWindow().setGravity(Gravity.BOTTOM);
        timing();
        LinearLayout line = (LinearLayout) findViewById(R.id.linear2);
        line.setOnTouchListener(this);
        line.removeAllViews();
        for (int i = 0; i < 15; i++) {
            TextView tv = new TextView(con);
            tv.setText("TestProcess " + i);
            tv.setTextColor(Color.BLACK);
            line.addView(tv);

        }

    }


    private void timing() {
        // TODO Auto-generated method stub
        if(flag==1){
        t.stop();

            flag=0;
        }

        t = new Thread(new Runnable() {

            public void run() {
                try {

                    t.sleep(3000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();

                }


                dismiss();

            }
        });
        t.start();
    }


    public boolean onTouch(View v, MotionEvent event) {
        System.out.println("touched");
        flag=1;
        timing();
        return false;
    }
}

Here thread is working perfectly as it will sleep after 3 seconds. But i need that the thread should get reset when we touched in the dialog and should sleep after 3 seconds from the touch. Please help me.
Thanks

  • 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-13T12:32:41+00:00Added an answer on June 13, 2026 at 12:32 pm

    You’ll need to test if it has been 3 seconds since that last touch before you call dismiss(); Here’s how I would do it.

    public class EventDialog2 extends Dialog implements OnTouchListener{
    
        TextView textv;
        Context con;
        Thread t;
        int flag=0;
        Long lastTouchHappenedAt = System.currentTimeMillis();
        Handler handle = new Handler();
    
        public EventDialog2(Context context, int dialogslideanim) {
            super(context, dialogslideanim);
            con = context;
    
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.dialog2);
            getWindow().setGravity(Gravity.BOTTOM);
            handle.postDelayed(delayDismis, 3000);
    
            LinearLayout line = (LinearLayout) findViewById(R.id.linear2);
            line.setOnTouchListener(this);
            line.removeAllViews();
            for (int i = 0; i < 15; i++) {
                TextView tv = new TextView(con);
                tv.setText("TestProcess " + i);
                tv.setTextColor(Color.BLACK);
                line.addView(tv);
    
            }
    
        }
    
    
        private Runnable delayDismis = new Runnable() {
            public void run() {
                    if(System.currentTimeMillis() - lastTouchHappenedAt >= 3000){
                        dismiss();
                        {
                }
            };
    
    
        public boolean onTouch(View v, MotionEvent event) {
            System.out.println("touched");
            flag=1;
            lastTouchHappenedAt = System.currentTimeMillis();
            handle.postDelayed(delayDismis, 3000);
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code: public class ColorTableDialog extends Dialog implements View.OnClickListener { public ColorTableDialog(Context
consider the following code: public class SynchronizedCounter extends Thread { private int c =
So i have this code: public class StreamingMp3Player extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener,
Here's my code: public class SomeName extends MapActivity implements OnClickListener, OnTouchListener{ public Timer t1
Here's my code: public class MyActivity extends Activity implements View.OnClickListener { private Button mHorizontalButton;
Here is my code: public class MainActivity extends Activity { private static final int
See this code: public class multiply { public Thread myThread; public int Counter {
I wrote this code: public class FileViewer extends JPanel implements ActionListener { /** *
I have the following code: public class AClass<X extends AnInterface> implements AnotherInterface { public
I have this code public class MyFragment extends SherlockFragment { public static Fragment newInstance(Context

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.