Android - Seekbar problem, unable to change value
Any help with this? I have an error when I try to use the seekbar to change my paint brush width. The error line is UNDER setStrokeWidth, saying "Is not applicable for the arguments (string)"
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawing_activity);
setCurrentPaint();
currentBrush = new PenBrush();
drawingSurface = (DrawingSurface) findViewById(R.id.drawingSurface);
drawingSurface.setOnTouchListener(this);
drawingSurface.previewPath = new DrawingPath();
drawingSurface.previewPath.path = new Path();
drawingSurface.previewPath.paint = getPreviewPaint();
redoBtn = (ImageButton) findViewById(R.id.redoBtn);
undoBtn = (ImageButton) findViewById(R.id.undoBtn);
redoBtn.setEnabled(false);
undoBtn.setEnabled(false);
//SEEKBAR THICKNESS CHANGE
//
//
SeekBar seekBar = (SeekBar)findViewById(R.id.seekBar);
final TextView seekBarValue = (TextView)findViewById(R.id.seekValue);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
seekBarValue.setText(String.valueOf(progress));
**currentPaint.setStrokeWidth(String.valueOf(progress));**
}
@Override
public void onStartTrackingTouch(SeekBar seekBar){
}
@Override
public void onStopTrackingTouch(SeekBar seekBar){
}
});
}
//END SEEKBAR THICKNESS
private void setCurrentPaint(){
currentPaint = new Paint();
currentPaint.setDither(true);
currentPaint.setColor(0xFFFFFFFF);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(3);
}
private Paint getPreviewPaint(){
final Paint previewPaint = new Paint();
previewPaint.setColor(0xFFC1C1C1);
previewPaint.setStyle(Paint.Style.STROKE);
prev开发者_开发技巧iewPaint.setStrokeJoin(Paint.Join.ROUND);
previewPaint.setStrokeCap(Paint.Cap.ROUND);
previewPaint.setStrokeWidth(3);
return previewPaint;
}
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
drawingSurface.isDrawing = true;
currentDrawingPath = new DrawingPath();
currentDrawingPath.paint = currentPaint;
currentDrawingPath.path = new Path();
currentBrush.mouseDown(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());
currentBrush.mouseDown(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
}else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
drawingSurface.isDrawing = true;
currentBrush.mouseMove( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
currentBrush.mouseMove(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
}else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
currentBrush.mouseUp(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
drawingSurface.previewPath.path = new Path();
drawingSurface.addDrawingPath(currentDrawingPath);
currentBrush.mouseUp( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
undoBtn.setEnabled(true);
redoBtn.setEnabled(false);
}
return true;
}
setStrokeWidth
takes a float
parameter, not a String
. Use currentPaint.setStrokeWidth(progress);
Replace currentPaint.setStrokeWidth(String.valueOf(progress)); with:
currentPaint.setStrokeWidth(progress);
You are trying to pass a string to setStrokeWidth thats why you get the error. Hope that helps. Good Luck!
精彩评论