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 7488829

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:03:37+00:00 2026-05-29T15:03:37+00:00

i am drawing a piechart by extending surfaceview to PieChart Class. now i am

  • 0

i am drawing a piechart by extending surfaceview to PieChart Class. now i am creating 2 objects for Piechart and adding to a VieWFlipper to swipe between those charts. now my problem is 2nd Piechart is not visible to the user if user swipes to 2nd view. but all the 2nd pies functionality is working. i am thinking like its refresh problem of the surfaceview.

any help on this will be appreciable. the following is my PieChart class.

class MyPieChart extends SurfaceView implements SurfaceHolder.Callback {

    @Override
    public void onDraw(Canvas canvas) {
        if (hasData) {
            resetColor();
            try {
                canvas.drawColor(getResources().getColor(R.color.graphbg_color));

                graphDraw(canvas);
            } catch (ValicException ex) {

            }

        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {

        Log.i("PieChart", "surfaceChanged");

    }

    public int callCount = 0;

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        if ((callCount++) % 2 == 0) {
            callCount = 1;
            try {
                 Log.i("PieChart", "surfaceCreated");
                mChartThread = new ChartThread(getHolder(), this);
                mChartThread.setRunning(true);

                if (!mChartThread.isAlive()) {
                    mChartThread.start();
                }

                mFrame = holder.getSurfaceFrame();

                mOvalF = new RectF(0, 0, mFrame.right, mFrame.right);

            } catch (Exception e) {
                // No error message required
            }
        }
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
         Log.i("PieChart", "surfaceDestroyed");
        boolean retry = true;
        callCount = 0;
        mChartThread.setRunning(false);
        while (retry) {
            try {
                mChartThread.join();
                retry = false;
            } catch (InterruptedException e) {
                // No error message required
            }
        }
    }
}

class ChartThread extends Thread {
    private SurfaceHolder mSurfaceHolder;
    private PieChart mPieChart;
    private boolean mRefresh = false;

    public ChartThread(SurfaceHolder surfaceHolder, PieChart pieChart) {
        // Log.i("ChartThread", "ChartThread");
        mSurfaceHolder = surfaceHolder;
        mPieChart = pieChart;
    }

    public void setRunning(boolean Refresh) {
        // Log.i("ChartThread", "setRunning : " + Refresh);
        mRefresh = Refresh;
    }

    @Override
    public void run() {
        Canvas c;
        // Log.i("ChartThread", "run : " + mRefresh);
        while (mRefresh) {
            c = null;
            try {
                c = mSurfaceHolder.lockCanvas(mPieChart.mFrame);
            //  c.drawColor(0xFFebf3f5);
                synchronized (mSurfaceHolder) {

                    mPieChart.onDraw(c);

                }
            } catch (Exception ex) {

            } finally {
                // do this in a finally so that if an exception is thrown
                // during the above, we don't leave the Surface in an
                // inconsistent state
                if (c != null) {
                    mSurfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
    }
}

here is my flipper.xml

<ViewFlipper  
android:id="@+id/flipper"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout  android:id="@+id/pie1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" />

<LinearLayout android:id="@+id/pie2" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" />

and i here is my activity

public class ViewFlipperActivity extends Activity {
    Button b1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        b1 = (Button)findViewById(R.id.submit1);

        b1.setOnClickListener(new View.OnClickListener() {
            ViewFlipper vflipper=(ViewFlipper)findViewById(R.id.flipper);   
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                vflipper.showNext();

            }
        });

    }

and i am dding the piecharts to Pie1 and Pie2 LinearLayouts in the Flipper.

both the pie’s are created and pasted on to the Pie Layouts. now if i move to the 2nd view in the flipper Pie1 is showing instead of pie2 and all other data and functionality which i am getting is related to Pie2. my doubt is Pie2 is rendering and hidden under Pie1. can any one help me on this with some solution.

i got a break through for this issue. which caused another issue with the following changes.

in flipper.xml replaced LinearLayout i place of view flipper.

    <LinearLayout  
    android:id="@+id/flipper"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout  android:id="@+id/pie1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" />

   </LinearLayout  >

and in ViewFlipperActivity

    public class ViewFlipperActivity extends Activity {
        Button b1;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            b1 = (Button)findViewById(R.id.submit1);

            b1.setOnClickListener(new View.OnClickListener() {
                LinearLayout vflipper=(LinearLayout)findViewById(R.id.flipper); 
LinearLayout pie1=(LinearLayout)findViewById(R.id.pie1);    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    vflipper.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));

pie1.removeAllViews();
pie1.addView(PieChart/SurfaceView);

                }
            });

        }

with the animation and is working fine and piechart is getting changed on the view. but block rect is getting visible from the surfaceview for a sec when swiping between piecharts. can some one help me on this issue.

  • 0 0 Answers
  • 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

Sidebar

Related Questions

i am drawing a piechart by extending surfaceview to PieChart Class. now i am
Whilst drawing on a SurfaceView, I'm having a problem intercepting a 'back' key press.
I have a problem drawing the legend of a pieChart with Core-Plot, because the
System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml
I have a problem drawing something quickly in .NET. I don't think that any
Drawing flat waves is easy, but I want to draw the wave between two
I'm drawing points on a map with OpenLayers like in this example: http://dev.openlayers.org/examples/draw-feature.html Now
Here I stuck with a problem in drawing the pie chart using coreplot in
Drawing a parallelgram is nicely supported with Graphics.DrawImage: Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height);
Drawing a blank on this, and google was not helpful. Want to make 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.