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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:39:16+00:00 2026-06-02T01:39:16+00:00

I am writing an Android app that needs to respond to touch events. I

  • 0

I am writing an Android app that needs to respond to touch events. I want my app to change the color of my list item to a custom color. I have written the following code, but only the MotionEvent.ACTION_DOWN section is working. The LogCat shows that ACTION_CANCEL and ACTION_UP aren’t called at all. Could you please help me understand why my code isn’t working.

This is my code…

view.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            view.setBackgroundColor(Color.rgb(1, 1, 1));
            Log.d("onTouch", "MotionEvent.ACTION_UP" );
        }
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            view.setBackgroundColor(Color.rgb(23, 128, 0));
            Log.d("onTouch", "MotionEvent.ACTION_DOWN" );
        }
        if (event.getAction() == MotionEvent.ACTION_CANCEL) {
            view.setBackgroundColor(Color.rgb(1, 1, 1));
            Log.d("onTouch", "MotionEvent.ACTION_CANCEL" );
        }
        return false;
    }
});
  • 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-02T01:39:17+00:00Added an answer on June 2, 2026 at 1:39 am

    If you return false from onTouch method, no further events get delivered to the listener. You should return true at least in case of event.getAction() == MotionEvent.ACTION_DOWN.

    Refactor your code as given below:

    view.setOnTouchListener(new OnTouchListener() {
    
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        view.setBackgroundColor(Color.rgb(1, 1, 1));
        Log.d("onTouch", "MotionEvent.ACTION_UP" );
    }
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        view.setBackgroundColor(Color.rgb(23, 128, 0));
        Log.d("onTouch", "MotionEvent.ACTION_DOWN" );
        return true;
    }
    
    if (event.getAction() == MotionEvent.ACTION_CANCEL) {
        view.setBackgroundColor(Color.rgb(1, 1, 1));
        Log.d("onTouch", "MotionEvent.ACTION_CANCEL" );
    }
    return false;
    }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an Android app that needs to access GMail, and I'd like to
So I'm writing an android app that needs to grab book price data from
I'm writing an Android app that contains a contact list. The design required me
I'm writing an app that needs to write events to a calendar in the
I'm writing an android app that has a standard activity, but also needs to
I'm writing an android app that has a standard activity, but also needs to
I am writing an application for Android that needs to respond as fast as
I'm writing an android app that needs to copy a file to the /system
I'm writing an app for android that needs to parse data from an XML
I'm writing an Android app that I want to use in conjunction with 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.