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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:13:47+00:00 2026-06-12T05:13:47+00:00

I want to implement chart like structure. For bar graph I’m using no. of

  • 0

I want to implement chart like structure.

For bar graph I’m using no. of buttons in my main activity and hence the output is as following :

screenshot


Then I’m creating new class which extends View in order to draw x and y axes for graph using canvas as following:

public class Draw extends View {

Paint paint = new Paint();

public Draw(Context context) {
    super(context);
    paint.setColor(Color.BLACK);
  }

@Override
public void onDraw(Canvas canvas) {

    canvas.drawLine(20, 50, 20, 200, paint);
    canvas.drawLine(20, 200, 200, 200, paint);
  }
}

But the problem is, after I use following lines of code in my main activity:

Draw draw = new Draw(this);
setContentView(draw);

I get following output as I’m setting the ContentView again:

screenshot


So my question is how do I integrate both these views in order to get below output:

screenshot

Is there any other way for doing the same?
ANY HELP APPRECIATED.

EDIT

Based on various suggestions, I removed

Draw draw = new Draw(this);
setContentView(draw);

from my activity class and instead put these lines in main xml layout.

<com.example.calci.Draw 
    android:id="@+id/draw" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" />

But I’m getting following EXCEPTION:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calci/com.example.calci.CalciActivity}: android.view.InflateException: Binary XML file line #468: Error inflating class com.example.calci.Draw

Caused by: java.lang.NoSuchMethodException: Draw(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)

EDIT 2

By adding AttributeSet attributeSet to constructor, I got the desired result.

But can anyone suggest whether I should use buttons or rectangles from canvas to draw bar graph.

Please note that I need to modify the height of the bar graphs dynamically based on seekbar value.

  • 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-12T05:13:48+00:00Added an answer on June 12, 2026 at 5:13 am

    If you are using xml for bar graph layout, you can include there your new created view like this:

    <view
        class="your.package.name.ProjectName$NameOfYourClass" 
        id="@+id/draw"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
    

    More about using custom components: http://developer.android.com/guide/topics/ui/custom-components.html

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

Sidebar

Related Questions

ExtJS Charts, I am using an Ext column chart and I want to implement
I want to implement a in-app chat view like the following pic. http://img408.imageshack.us/img408/4057/img0139.png How
I'm trying to implement the Candlestick Google Chart, but I want to be able
I want to create a component which can be used like: <mc:chart data=#{bean.data} width=200
I want to implement is_pointer. I want something like this: template <typename T >
I want to implement a Omegle like chat system on a website, which will
I want to implement a facebook like notification system in ASP.NET MVC 3 :
i am preparing mvc4 website in which i want to implement chart for specific
I have to implement gtalk like chat application using UDP in java. i have
As a personal exercise, I want to implement the visitor pattern using shared_ptr. I

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.