android.view.Viewを拡張するカスタムクラスにいくつかのデータを渡したいと思います。カスタムViewクラスにデータを渡す
を はしかし、私はそれを言って、警告メッセージが表示されますカスタムビューLinePlotはツールによって使用コンストラクタ欠落しています:(コンテキスト) または(コンテキスト、属性セット)または(コンテキスト、属性セット、int型)
しかし、私はコードを実行し、すべてがスムーズに動作するようです。
- 何が起こっているか
- データをクラスにどのように渡す必要がありますか?
- カスタムコンストラクタを使用できないのはなぜですか?
ありがとう!
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;
import java.util.ArrayList;
public class LinePlot extends View {
private ArrayList<Float> mPoints;
private int dx;
private int dy;
Paint paint=new Paint();
public LinePlot(Context context,int dx_plot, int dy_plot, ArrayList<Float> points) {
super(context);
mPoints=points;
dx=dx_plot;
dy=dy_plot;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// plotting my data here
}
}
カスタム 'View'のインスタンスをどのように作成しますか?レイアウト 'xml'ファイルを通して?またはプログラム的に? –
カスタム 'View'のインスタンスをプログラムで作成します。私は自分の.xmlに 'FrameLayout'を持っています。' frameLayout.addView(linePlot) 'を実行して' LinePlot'オブジェクトを追加します。 –