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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:27:28+00:00 2026-06-06T14:27:28+00:00

So I have this class which extends an activity. But I want to draw

  • 0

So I have this class which extends an activity. But I want to draw something on the screen, so I need to make a canvas. However I can’t extends View, because it’s an activity allready. What should I do?

My activity has the onClick method which I use to do some stuff, but what I wanna do is draw a simple image when I call the onClick method as well.

Thanks.

public class Stuff extends Activity implements OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
(...)
}

@Override
public void onClick(View arg0) {
(...)
}
  • 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-06T14:27:31+00:00Added an answer on June 6, 2026 at 2:27 pm

    STEP 1: create a class by extends View as:

    public class DrawView extends View {  
        public float currentX=40;  
        public float currentY=50;  
    
        public DrawView(Context context) {  
            super(context);  
            // TODO Auto-generated constructor stub  
        }  
    
        @Override  
        protected void onDraw(Canvas canvas) {        
            super.onDraw(canvas);   
            Paint paint=new Paint();  
            paint.setColor(Color.RED);  
            canvas.drawCircle(currentX, currentY, 25, paint);  
        }  
    
    } 
    

    STEP 2: In Your Stuff Activity :

    public class Stuff extends Activity implements OnClickListener {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.main);  
    LinearLayout root=(LinearLayout) findViewById(R.id.root); 
    (...)
    }
    
    @Override
    public void onClick(View arg0) {
    //DRAW YOUR VIEW ON BUTTON CLICK
    final DrawView drawView=new DrawView(this);  
    drawView.setMinimumWidth(300);  
    drawView.setMinimumHeight(500);
    drawView.currentX=200;  
    drawView.currentY=200;  
    drawView.invalidate(); 
    root.addView(drawView);
    (...)
    }
    

    STEP 3: Your Activity main.xml as :

    <?xml version="1.0" encoding="utf-8"?>  
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        android:orientation="vertical"   
        android:background="#99FFCC"  
        android:id="@+id/root">  
    </LinearLayout>
    

    and finally try to search on google before asking question here.thanks

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

Sidebar

Related Questions

I have class A which extends the Activity class. This class is in package
So I have this loader class which extends AsyncTask. Then I do new loader().execute();
I have a class which extends JPanel, inside this panel i have added a
Hi Experts: I have a class which extends JPanel now ShapePanel (Sp) this gets
I have this class which I want to pass around Windows as LPARAM parameter.
I have an object which looks something like this class MyObject { string Name;
my question is simple. I have class TouchSurfaceView which extends GLSurfaceView. I want create
I have a class which extends the Runnable . This class performs some heavy
I am creating one parent Activity(Class) and then want to extends this class to
I have a class which has implemented INotifyPropertyChanged . This class UserInfo has 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.