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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:23:58+00:00 2026-06-03T22:23:58+00:00

Thanx for taking the time to look at the question. I am trying out

  • 0

Thanx for taking the time to look at the question. I am trying out some android programming and I have hit a wall; not sure how to solve it. I am trying activate an animation for a specific entity only when touch count is odd. That is touchCount%2 != 0.

public boolean onTouch(View v, MotionEvent event){

    ArrayList<TextView> textToDance = new ArrayList<TextView>();
    textToDance.add((TextView)findViewById(R.id.CAD5));
    textToDance.add((TextView)findViewById(R.id.CAD10));
    textToDance.add((TextView)findViewById(R.id.CAD20));
    textToDance.add((TextView)findViewById(R.id.CAD50));
    textToDance.add((TextView)findViewById(R.id.CAD100));

    switch (event.getAction()){
        case MotionEvent.ACTION_DOWN:
            for(TextView txtAnimate: textToDance){

                if(event.getRawX()<= txtAnimate.getX()+txtAnimate.getMeasuredWidth() && event.getRawX()>=txtAnimate.getX()){
                    if(event.getRawY()<= txtAnimate.getY()+105+txtAnimate.getMeasuredHeight() && event.getRawY()>=txtAnimate.getY()+105){
                        helpAnimate(txtAnimate, 0);
                    }
                }

            }

        break;

        case MotionEvent.ACTION_MOVE:
            Log.d("MOVE","MOVE");
        break;

        case MotionEvent.ACTION_UP:
            Log.d("UP","UP");
        break;

        default:
            break;
    }
    return true;
}

I tried to implement a HashMap but that map gets reset everything onTouch is called. Any suggestions?

  • 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-03T22:24:01+00:00Added an answer on June 3, 2026 at 10:24 pm

    Firstly, you want to initialize your array outside of the onTouch method.

    ArrayList<TextView> textToDance = new ArrayList<TextView>();
    textToDance.add((TextView)findViewById(R.id.CAD5));
    textToDance.add((TextView)findViewById(R.id.CAD10));
    textToDance.add((TextView)findViewById(R.id.CAD20));
    textToDance.add((TextView)findViewById(R.id.CAD50));
    textToDance.add((TextView)findViewById(R.id.CAD100));
    

    Then you could create a map and initialize it with zero count values and register an onTouchListener (let’s assume its your Activity)

    HashMap<TextView,Integer> myMap = new HashMap<TextView,Integer>();
    for (TextView tv : textToDance){
        tv.setOnTouchListener(this);
        myMap.put(tv,0);
    
    } 
    

    Then in onTouch you would have something like…

    public boolean onTouch(View v, MotionEvent event){
        switch (event.getAction()){
           case MotionEvent.ACTION_DOWN:
              if (myMap.contains(v)){
                  myMap.put(v, myMap.get(v) + 1;
              }
           break;
    

    This probably isn’t the most optimal way but it should be enough to get you started with achieving the kind of thing you’re looking to do.

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

Sidebar

Related Questions

I spent some time trying to generate certain tab icons using Android Asset Studio
Thank you for taking the time to look at my post. I have an
and thanks for taking a look at the question. The background I have several
Thank you for taking the time to look at my question. I've seen similar
thank you for taking time to look at this. I am trying to code
Thank you for taking the time to look at my question. I'm using django
Hi All and thank you for taking the time to look at my question.
Thank you for taking the time to look at my post. I have a
Hello and thank you for taking the time to read my question, I have
First off, let me thank you if you're taking the time to look at

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.