現在、線を引くアプリを開発中です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();
}
});
前もって感謝します!