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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:56:25+00:00 2026-06-04T16:56:25+00:00

I am using a custom view component to draw a pie ( a simple

  • 0

I am using a custom view component to draw a pie ( a simple pie) . Each list Item has a pie with different values.

Now when I use it in a list view the pie values are shuffled and sometimes not updated.
My default pie value is 1.
When I first open my list
the first item shows proper value rest of the list items show only the defalt value 1 regardless of the actual value.

When I scroll the list the pie get value but that are shuffled . The first item has value of 5th , 2nd has value of 3rd and 3rd has value of something else.

Code of custom view:

    public class PieRating extends View{
    private float Rate;
    private Paint p;
    private int startX;
    private int startY;
    private int radius;
    private ArrayList<Integer> colors;
    private ArrayList<Float> values;
    Bitmap bitmap;
    Context mContext;
    public PieRating(Context context, AttributeSet attrs) {
        super(context, attrs);

        Rate=1;
        mContext = context;

        p = new Paint();
        p.setAntiAlias(true);

        colors = new ArrayList<Integer>();
        values = new ArrayList<Float>();

        startX = 0;
        startY = 0;
        radius = 20;

        colors.add(Color.GRAY);
        colors.add(Color.TRANSPARENT);

        values.add(Rate);
        values.add(5 - Rate);

    }

    public void setRating(float Rate) {
        this.Rate = Rate;
        values.clear();
        values.add(Rate);
        values.add(5 - Rate);

    }

    public float getRating(){
        return Rate;


    }

    @Override
    protected void onDraw(Canvas canvas) {

        float offset = 0;
        float sum = 0;
        for (int a = 0; a < values.size(); a++) {
            sum += values.get(a);
        }

        float angle = (float) (360 / sum);

        RectF rectF = new RectF();
        rectF.set(getStartX(), getStartY(), getStartX() + getRadius(),
                getStartY() + getRadius());

        for (int i = 0; i < values.size(); i++) {

            p.setColor(colors.get(i));

            if (i == 0) {
                canvas.drawArc(rectF, 270, values.get(i) * angle, true, p);
            } 
            else {
                canvas.drawArc(rectF, offset, values.get(i) * angle, true, p);
            }

            offset += (values.get(i) * angle + 270);
        }

        canvas.save();

    }


    public int getStartX() {
        return startX;
    }

    public void setStartX(int startX) {
        this.startX = startX;
    }

    public int getStartY() {
        return startY;
    }

    public void setStartY(int startY) {
        this.startY = startY;
    }

    public int getRadius() {
        return radius;
    }

    public void setRadius(int radius) {
        this.radius = radius;
    }

    public ArrayList<Integer> getColors() {
        return colors;
    }

    public void setColors(ArrayList<Integer> colors) {
        this.colors = colors;
    }   

    public ArrayList<Float> getValues() {
        return values;
    }

    public void setValues(ArrayList<Float> values) {
        this.values = values;
    }
}

And my list

public View getView(int position, View convertView, ViewGroup parent) {


PieRating pr =((PieRating)findViewById(R.id.score_pie_container));
            try
            {
            float rating = Float.parseFloat(JSONHelper.getString(mRestaurants, "restaurants.restaurant[].opinion.general", new int[] { position }));
            pr.setRating(rating);
            }
            catch (Exception e) {
                // TODO: handle exception
            }
}

Tried calling pr.invalidate once I set rating but no good.

  • 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-04T16:56:26+00:00Added an answer on June 4, 2026 at 4:56 pm

    silly mistake

    ((PieRating)convertView.findViewById(R.id.score_pie_container))

    I missed the convertView part ..

    Leaving answer just in case someone runs into similar issue

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

Sidebar

Related Questions

I am using custom row view in ListView widget. I am having getView method
In my custom view I'm looking into using Canvas.getClipBounds() to optimize my onDraw method
I am using apple's custom table view cell code and modifying the drawRect code
Here's the code I'm using to make a custom AlertDialog. public void onButtonClicked(View v)
I'm using custom renderer on JList, but none of components rendered are accessible. list.setCellRenderer(new
I am using custom fonts in my website. I could use a local font
I have a custom UIImageView class that creates thumbnails (UIImageView) and each thumbnail has
I am using custom table view cell to show to table view - (id)initWithFrame:(CGRect)frame
I have created custom component for displaying text with either Simple or Password mode,
I am using Joomla 1.5 . I have developed a custom component that's basically

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.