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

The Archive Base Latest Questions

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

I am new for android. I want to add image button in onDraw. I

  • 0

I am new for android. I want to add image button in onDraw. I wonder if I can do like this. I don’t have compile error. But simulator says, “Unfortunately MyApp has stopped.”
My second question is how can I add button at x, y location in screen?
There is no location parameters in addView.

protected class MyLayout extends LinearLayout {
    ImageButton button;
    public MyLayout(Context context) {
        super(context);
        setWillNotDraw(false);
        button = new ImageButton(context);
        button.setImageBitmap(buttonBitmap); // buttonBitmap is loaded in onCreate
    }
    public void onDraw(Canvas canvas) {
        addView(button);
    }
}
  • 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:07:01+00:00Added an answer on June 2, 2026 at 1:07 am

    I would not be adding a button to a custom linearlayout in the onDraw() override function. onDraw is called periodically (for example when the element is resized). So you will be adding the same button EACH time onDraw() is called. And you will get an error if you add the same item more than once.

    What exactly are you trying to do? If you want to just add a button to a linear layout, you can do so without extending a layout.

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

Sidebar

Related Questions

i'm new to android.I want to add values to the listview as below.I have
I am new to Android. In my application I want to add an process
I have this widget in android, that displays an image and gets updated periodically
I am new to Android. I want to add one Menu by pressing the
I want to add a new image view at the location where user touch
I am new in Android. I want to add one custom Confirmation before uninstall
I have a project in Android and I want to add MapView to it.
I have android app which works fine. And now I want to add some
Im new to android and I want to create kind of CRUD with SQLite.
Hi i'm new to android my client want to run the app in their

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.