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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:00:20+00:00 2026-06-12T01:00:20+00:00

I am trying to make a simple custom view which is not working. I

  • 0

I am trying to make a simple custom view which is not working. I refereed the custom view class from layout resource file. But its not working. Can anybody tell me where the problem is.

public class WriteOnScreenActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

}

public class CustomView extends View {

    private Paint paint;

    public TouchEventView(Context context) {
        super(context);

        paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(25);
        paint.setAntiAlias(true);
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    canvas.drawText("Hello World", 5, 30, paint);   
    }

}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

       <com.example.touch.CustomView
           android:id="@+id/TouchEventView"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent" />

</RelativeLayout>
  • 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-12T01:00:22+00:00Added an answer on June 12, 2026 at 1:00 am

    Move the definition of your class TouchEventView into a new file.

    And here’s the fix.

    public class TouchEventView extends View {
    
        private Paint paint;
    
        public TouchEventView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            setup(context, attrs, defStyle);
        }
    
        public TouchEventView(Context context, AttributeSet attrs) {
            super(context, attrs);
            setup(context, attrs, 0);
        }
    
        public TouchEventView(Context context) {
            super(context);
    
          setup(context, null, 0);
    
        }
    
        private void setup(Context context, AttributeSet attrs, int defStyle)
        {
    
                paint = new Paint();
                paint.setColor(Color.RED);
                paint.setTextSize(25);
                paint.setAntiAlias(true);
        }
    
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
        canvas.drawText("Hello World", 5, 30, paint);   
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make simple minesweeper game in python, but have one problem. I have
I'm trying to make simple website with content background combined from 3 images: top
I am fairly new to iOS development and trying make a simple app which
im trying to make a simple search on my database from the index action
I'm trying to make a custom dialog to show a view in this dialog.
I'm trying to make a simple xml-editor for some basic but specific needs, the
I'm trying to make a simple custom field field_book_year for the new node type
I'm trying to make a custom JDialog using windowBuilder, but at the very beginning
I am trying to make simple custom tags to allow custom templates on my
I was trying to make an app with a custom view, and i kept

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.