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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:03:44+00:00 2026-06-04T02:03:44+00:00

I know how to make it so you will open a new page onClick

  • 0

I know how to make it so you will open a new page onClick but when I put the same code into onTouch it doesnt work? This is the code I have… any help for me if I click on the error I get a message saying “The constructor Intent(Tab3, Class) is undefined” and it wants me to set it to “= new Intent” but that doesnt make sence to me.

public boolean onTouch(View v, MotionEvent event) 
    {
        if(rect2.contains((int) event.getX(),(int) event.getY()))
        {
            Intent SectionManager = new Intent (this, SectionManager.class);
            startActivity (SectionManager);
        }
        return true;
    }

EDIT
more information on my code!

public class Tab3 extends View implements OnTouchListener
{
    LinearLayout myLayout;
    int x1, x2, y1, y2, x, y;
    // x, y;
    Rect rect2 = new Rect();

    public Tab3(Context context, AttributeSet attrs)
    {
        super (context, attrs);

        myLayout = (LinearLayout) findViewById(R.id.myLayout);

        x1 = 0;
        x2 = 300;               //1280 by 748
        y1 = 0;
        y2 = 300;




        setFocusable(true);
        setFocusableInTouchMode(true); 
        setOnTouchListener(this);
        requestFocus();
    }

    @Override
    protected void onDraw(Canvas canvas) 
    {
        super.onDraw(canvas);

        Paint blue = new Paint();
        blue.setColor(Color.BLUE);
        canvas.drawRect(rect2, blue);
        rect2.set(x1, y1, x2, y2);

        invalidate();
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        if(rect2.contains((int) event.getX(),(int) event.getY()))
        {
            Intent SectionManager = new Intent (Tab3.this, SectionManager.class);
            startActivity (SectionManager);
        }
        return true;
    }
}
  • 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-04T02:03:45+00:00Added an answer on June 4, 2026 at 2:03 am

    your context is wrong you need to use YourClassName.this inside there not just this. currently this means the view aka Tab3 which is not the context

    public class MyActivity extends Activity{
                .
                all your activity stuff here
                .
                .
    public class Tab3 extends View implements OnTouchListener{
    
    LinearLayout myLayout;
    int x1, x2, y1, y2, x, y;
    // x, y;
    Rect rect2 = new Rect();
    
    public Tab3(Context context, AttributeSet attrs)
    {
        super (context, attrs);
    
        myLayout = (LinearLayout) findViewById(R.id.myLayout);
    
        x1 = 0;
        x2 = 300;               //1280 by 748
        y1 = 0;
        y2 = 300;
    
    
    
    
        setFocusable(true);
        setFocusableInTouchMode(true); 
        setOnTouchListener(this);
        requestFocus();
    }
    
    @Override
    protected void onDraw(Canvas canvas) 
    {
        super.onDraw(canvas);
    
        Paint blue = new Paint();
        blue.setColor(Color.BLUE);
        canvas.drawRect(rect2, blue);
        rect2.set(x1, y1, x2, y2);
    
        invalidate();
    }
    
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        if(rect2.contains((int) event.getX(),(int) event.getY()))
        {
            Intent SectionManager = new Intent (MyActivity.this, SectionManager.class);
            startActivity (SectionManager);
        }
        return true;
    }
    } //end Tab3 Class
    } //end MyActivity
    

    Tab3 is a sub class of MyActivity now and you should be able to do MyActivity.this

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

Sidebar

Related Questions

I'm thinking about frameworks. I know they make life a lot easier, but as
I know how to make the intellisense work in a .js file using this
I know how to make the list of the Fibonacci numbers, but i don't
does anybody know how to make EJBTimers persistent not in filesystem, but in selected
I don't know what's make wrong, my map can load, but the image on
I'm writing a bit of code that will open a MessageBox on a separate
I have a page which open a new window with External Url (Twitter Authentication
I want to know whether unhandled exception will make WCF service crash. I have
I'm curious to know how the new security model in OS X Lion will
Hey I am very new to python but I am trying to make 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.