Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to increase/decrease STROKE width on clickListener in android
    text
    copied!<p>I m making paint app in android.but i have one problem i want to change STROKE width or brush size increase or decrease on clickListeners.but the problem is that i select the new width brush first time not change his width and second time when i draw the brush width is changed.so what can i do so that i solve the problem.please help. this is my code</p> <pre><code>int Stork_Width=0; but1 = (Button) dialog.findViewById(R.id.but1); // if button is clicked, close the custom dialog but1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //idd=mMaindialog.get(position).imagename; Stork_Width=10; mPaint.setStrokeWidth(Stork_Width); dialog.dismiss(); } }); but2 = (Button) dialog.findViewById(R.id.but2); // if button is clicked, close the custom dialog but2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Stork_Width=15; mPaint.setStrokeWidth(Stork_Width); dialog.dismiss(); } }); but3 = (Button) dialog.findViewById(R.id.but3); // if button is clicked, close the custom dialog but3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Stork_Width=25; mPaint.setStrokeWidth(Stork_Width); dialog.dismiss(); } }); now i create the method of Brushes : and strore the path in Hashmap also: private Map&lt;Path, Integer&gt; colorwidth = new HashMap&lt;Path, Integer&gt;(); private Paint createBrush(final int width) { // TODO Auto-generated method stub mPaint1 = new Paint(); mPaint1.setColor(colorPicked); mPaint1.setAntiAlias(true); mPaint1.setDither(true); mPaint1.setStyle(Paint.Style.STROKE); mPaint1.setStrokeJoin(Paint.Join.ROUND); mPaint1.setStrokeCap(Paint.Cap.ROUND); mPaint1.setStrokeWidth(width); return mPaint1; } ontouch activity:: @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // touch_start(x, y); // invalidate(); undonePaths.clear(); mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; invalidate(); break; case MotionEvent.ACTION_MOVE: // touch_move(x, y); // invalidate(); float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx &gt;= TOUCH_TOLERANCE || dy &gt;= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2); mX = x; mY = y; } invalidate(); break; case MotionEvent.ACTION_UP: // touch_up(); // invalidate(); mPath.lineTo(mX, mY); mMaindialog.add(mPath); colorsMap.put(mPath, slll); colorwidth.put(mPath, Stork_Width); mPath = new Path(); mPath.reset(); invalidate(); break; } return true; </code></pre>
 

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