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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:51:58+00:00 2026-05-29T18:51:58+00:00

I have extended the android View class, and now I want to define a

  • 0

I have extended the android View class, and now I want to define a method in the view that launches when the view is longClicked.

I already have actions for the motionevents using public boolean onTouchEvent(MotionEvent event). This method doesn’t allow for long clicks to take action upon.

I want to do it in the extended View class itself. I’m aware that I can add an OnLongClickListener to the view in the activity, but I’d like to know if there’s a way to implement this in the View itself.

public class ArchitectureView extends GraphView implements OnLongClickListener {

public ArchitectureView(Context context) {
    super(context);
    this.setOnLongClickListener(this);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            break;

        case MotionEvent.ACTION_UP:
            break;

        case MotionEvent.ACTION_CANCEL:
            break;

    }

    return true;
}

@Override
public boolean onLongClick(View v) {
    Log.e("I've been", "longclicked");
    return false;
}

}

GraphView is extended from View and also overrides onTouchEvent and calles super

  • 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-05-29T18:52:01+00:00Added an answer on May 29, 2026 at 6:52 pm

    can you post your onTouchEvent() Method?

    I think you’ll have to implement the parameters for the longpress as logic inside your that touch event callback.

    In order to do so you’d have to test for the “pattern” of a longpress

    something like if(ACTION_UP_TIME < (ACTION_DOWN_TIME + someMillis))

    EDIT: Upon thinking about it more, couldn’t you just implement OnLongClickListener on your view object, then override the onLongClick() Callback?

    Like this:

    public class TestView extends View implements OnLongClickListener{
    
    public TestView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    
        //I am not certain if you'd need the next line or not.
        this.setOnLongClickListener(this);
    }
    
    
    @Override
    public boolean onLongClick(View v){
        //do things
    
        return false;
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an extended dialog class that I want to show for 3 seconds
I have to open a page from class extended from javax.swing.AbstractAction class... Is that
I have an Activity that pulls an object from an Application extended class (application
I have two questions, if you have extended a view such that you new
I have an Android app where I've extended the base Application class in order
I have extended the ASP.NET MVC Html Helper to include my own ValidationImage that
I am trying to draw an animation. To do so I have extended View
Hello I have an extended stored procedure that sends an error message. srv_sendmsg(pSrvProc, SRV_MSG_ERROR,
I have extended my class with a dialog in which I have set content
I am trying to create a simple 3-D app for android that will have

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.