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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:09:53+00:00 2026-06-09T23:09:53+00:00

My program gives the user an instruction and then they have n seconds to

  • 0

My program gives the user an instruction and then they have n seconds to respond. However when it asks you to Do Nothing the text view doesn’t update at all, the other instructions pop up fine and they’re all coded the same.

    public class SimpleActivity extends Activity implements SimpleGestureListener {

    String str = "";
    String strDirection = "";
    Random ranDirection = new Random();
    int intDirection;

    int scoreCounter;
    long timeStart;
    long timeEnd;

    TextView score;
    TextView allerts;
    TextView correct;

    private SimpleGestureFilter detector;

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gesture);
        detector = new SimpleGestureFilter(this, this);

        scoreCounter = 0;
        catchValues();

    }

    public boolean dispatchTouchEvent(MotionEvent me) {
        this.detector.onTouchEvent(me);
        return super.dispatchTouchEvent(me);
    }

    public void catchValues() {

        /** Linked to gesture.xml */

        score = (TextView) findViewById(R.id.tvScore);
        allerts = (TextView) findViewById(R.id.tvAllerts);
        correct = (TextView) findViewById(R.id.tvCorrect);

        initiateRandom();

    }

    public void initiateRandom() {

        /** Generate random move */

        /** Log start time of move */

        long start = System.currentTimeMillis();
        timeStart = start;

        intDirection = ranDirection.nextInt(5);

        if (intDirection == 0) {
            allerts.setText("Please Swipe Up!");
            randomColour();
        } else if (intDirection == 1) {
            allerts.setText("Please Swipe Down!");
            randomColour();
        } else if (intDirection == 2) {
            allerts.setText("Please Swipe Left!");
            randomColour();
        } else if (intDirection == 3) {
            allerts.setText("Please Swipe Right!");
            randomColour();
        } else if (intDirection == 4) {
            allerts.setText("Do Nothing!");
            randomColour();

            doNothing();

        }

    }

    public void onSwipe(int direction) {

        /** Detect swipe and store result */

        switch (direction) {

        case SimpleGestureFilter.SWIPE_RIGHT:
            strDirection = "right";

            break;
        case SimpleGestureFilter.SWIPE_LEFT:
            strDirection = "left";

            break;
        case SimpleGestureFilter.SWIPE_DOWN:
            strDirection = "down";

            break;
        case SimpleGestureFilter.SWIPE_UP:
            strDirection = "up";


            break;
        }

        checkSwipe();

    }

    public void checkSwipe() {

        /** Compare time from instruction to action */

        long end = System.currentTimeMillis();
        timeEnd = end;

        /** Verify the action was correct */

        if (timeEnd < timeStart + 2000) {

            if (intDirection == 0) {
                if (strDirection.contentEquals("up")) {
                    correctSwipe();
                } else {
                    wrongSwipe();
                }

            } else if (intDirection == 1) {
                if (strDirection.contentEquals("down")) {
                    correctSwipe();
                } else {
                    wrongSwipe();
                }
            } else if (intDirection == 2) {
                if (strDirection.contentEquals("left")) {
                    correctSwipe();
                } else {
                    wrongSwipe();
                }
            } else if (intDirection == 3) {
                if (strDirection.contentEquals("right")) {
                    correctSwipe();
                } else {
                    wrongSwipe();
                }

            }

        } else {

            /** Incorrect action, reset score and start over */

            scoreCounter = 0;
            score.setText("Score:" + scoreCounter);
            strDirection = "";
            correct.setText("Too Slow!");
            initiateRandom();

        }

    }

    @Override
    public void onDoubleTap() {
        // TODO Auto-generated method stub

    }

    public void correctSwipe() {
        scoreCounter = scoreCounter + 100;
        score.setText("Score:" + scoreCounter);
        correct.setText("Correct!");
        strDirection = "";
        initiateRandom();

    }

    public void wrongSwipe() {
        correct.setText("Wrong!");
        scoreCounter = 0;
        strDirection = "";
        score.setText("Score:" + scoreCounter);

    }

    public void randomColour() {

        Random txtColor = new Random();

        allerts.setTextColor(Color.rgb(txtColor.nextInt(255),
                txtColor.nextInt(255), txtColor.nextInt(255)));
    }

    public void doNothing() {

        /** Does nothing for n seconds */

        long end = System.currentTimeMillis();
        timeEnd = end;

        while (timeEnd < timeStart + 2000) {

            timeEnd = System.currentTimeMillis();
        }

        if (strDirection.contentEquals("up")
                || strDirection.contentEquals("down")
                || strDirection.contentEquals("left")
                || strDirection.contentEquals("right")) {
            wrongSwipe();
        } else {
            correctSwipe();
        }

    }

}
  • 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-09T23:09:55+00:00Added an answer on June 9, 2026 at 11:09 pm

    Try using runOnUiThread(Runnable r) when you want to update your UI from a Non-UI Thread:

    Runs the specified action on the UI thread. If the current thread is
    the UI thread, then the action is executed immediately. If the current
    thread is not the UI thread, the action is posted to the event queue
    of the UI thread.

    Something like:

     Activity_Name.this.runOnUiThread(new Runnable() {
    
            @Override
            public void run() {
                // here you put updates to the UI
    
            }
        });
    

    Alternatively use onProgressUpdate() method of AsyncTask.

    Reference:

    • http://developer.android.com/reference/android/app/Activity.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main array in the program that the user gives the index
Changing a Linux C++ program which gives the user limited file access. Thus the
I have to write a program in python where the user is given a
This program is meant to generate a dynamic array, however it gives an access
I have been trying to write some code that asks the user for several
I'm trying to validate that the input a user gives my program via gets
i have link php program - its activation link as activation.php?user=jack?hash=abcd?id=20 When i use
I'm writing a program that calculates input a user gives, simple numbers. 2, 4,
Here is a simple php program which gives a strange output. Can anyone explain
when I'm trying to compile my c program it gives me this error warning:

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.