现在我正在开发可以在onClick
. 我在LineView.java
课堂上画线并onClick
在MainActivity.java
. 为了解决这个问题,我检查了类似的问题。第一个解决方案:
LineView.onDraw();
它给了我这个错误:
Multiple markers at this line
- The method onDraw(Canvas) in the type LineView is not applicable for the
arguments ()
- Suspicious method call; should probably call "draw" rather than "onDraw"
我也尝试在 MainActivity 中编写:
LineView lineView = new LineView(null);
lineView.onDraw();
但它也给出了一个错误:
Multiple markers at this line
- The method onDraw(Canvas) in the type LineView is not applicable for the
arguments ()
- Suspicious method call; should probably call "draw" rather than "onDraw"
这是我的 LineView.java:
public class LineView extends View {
Paint paint = new Paint();
Point A;
Point B;
boolean draw = false;
public void onCreate(Bundle savedInstanceState) {
}
public LineView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LineView(Context context, AttributeSet attrs, int defstyle) {
super(context, attrs, defstyle );
}
public LineView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
draw = MainActivity.draw;
if(draw){
//A = (getIntent().getParcelableExtra("PointA"));
A = MainActivity.A;
B = MainActivity.B;
canvas.drawLine(A.x, A.y, B.x, B.y, paint);
}
}
private Intent getIntent() {
// TODO Auto-generated method stub
return null;
}
}
我的MainActivity.java
onClick
:
@Override
public void onClick(View v) {
draw = true;
LineView.onDraw();
}
});
提前致谢!