Note that there are some explanatory texts on larger screens.

plurals
  1. POrendaring issue with surfaceview in viewflipper?
    primarykey
    data
    text
    <p>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.</p> <p>any help on this will be appreciable. the following is my PieChart class. </p> <pre><code>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); } } } } } </code></pre> <p>here is my flipper.xml</p> <pre><code>&lt;ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id="@+id/pie1" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;LinearLayout android:id="@+id/pie2" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; </code></pre> <p></p> <p>and i here is my activity</p> <pre><code>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(); } }); } </code></pre> <p>and i am dding the piecharts to Pie1 and Pie2 LinearLayouts in the Flipper.</p> <p>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.</p> <p>i got a break through for this issue. which caused another issue with the following changes.</p> <p>in flipper.xml replaced LinearLayout i place of view flipper.</p> <pre><code> &lt;LinearLayout android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:id="@+id/pie1" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout &gt; </code></pre> <p>and in ViewFlipperActivity</p> <pre><code> 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); } }); } </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload