Note that there are some explanatory texts on larger screens.

plurals
  1. POReloading of Custom View on clicking a Button
    text
    copied!<p>I m trying to refresh the screen on clicking a button so i want to know What should I write in OnClick() method so that the custom view ie TouchEventView will reload or refresh here is my code of TouchEventView.java </p> <pre><code>public class TouchEventView extends View { private Paint paint = new Paint(); private Path path = new Path(); public TouchEventView(Context context, AttributeSet attrs) { super(context, attrs); paint.setAntiAlias(true); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeWidth(5f); } @Override protected void onDraw(Canvas canvas) { canvas.drawPath(path, paint); } @Override public boolean onTouchEvent(MotionEvent event) { float eventX = event.getX(); float eventY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: path.moveTo(eventX, eventY); return true; case MotionEvent.ACTION_MOVE: path.lineTo(eventX, eventY); break; case MotionEvent.ACTION_UP: // nothing to do break; default: return false; } // Schedules a repaint. invalidate(); return true; } } ` </code></pre> <p>here is main.xml file ``</p> <pre><code> &lt;de.vogella.android.touch.TouchEventView android:id="@+id/mydrawview1" android:layout_width="wrap_content" android:layout_height="328dp" android:layout_weight="0.91" /&gt; &lt;LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;Button android:id="@+id/reset" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Reset" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt;` </code></pre> <p>here is activity class`</p> <pre><code>/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button res = (Button) findViewById(R.id.reset); res.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub TouchEventView touchView = (TouchEventView) findViewById(R.id.mydrawview1); touchView.clear(); } }); } </code></pre> <p>}` </p>
 

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