短くします。
私は Android のメモ作成プログラムを開発しています。これが私がやりたいことです: ビューを拡張するカスタム クラスがあり、プログラムの起動時 (onCreate) に、このカスタム ビュー (View01 という名前) をメイン レイアウトに追加します。次に、現在のビュー (View01) をダブルクリックしたときに、別のビュー (メイン レイアウトまたは他の可能なレイアウト) を追加したいと考えています。私のコードは次のようなものです:(これは View01 の onTouchEvent 関数の一部です)
public class NotePanel extends View {
private long startTime;
private long endTime;
private DrawPanel drawPanel;
private LinearLayout drawLayout;
final private int pressingTime = 600;
private Context applicationContext;
public NotePanel(Context applicationContext) {
// TODO Auto-generated constructor stub
super(applicationContext);
//this.applicationContext = applicationContext;
startTime=0;
endTime=0;
this.setBackgroundColor(Color.BLUE);
}
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getActionMasked() == MotionEvent.ACTION_DOWN){
startTime = System.currentTimeMillis();
System.out.println("click");
}
if(event.getActionMasked() == MotionEvent.ACTION_UP){
endTime = System.currentTimeMillis();
System.out.println(endTime-startTime);
if (endTime-startTime >= pressingTime){
drawPanel = new DrawPanel(this.applicationContext);
//drawPanel.setVisibility(GONE);
drawPanel.setBackgroundColor(Color.RED);
//drawLayout = new LinearLayout(applicationContext);
drawLayout.addView(drawPanel);
}
}
return true;
}
問題は、View01 の drawLayout に対して何もできないことです。私は Android 開発に慣れていないので、ここで困惑しています。「アクティビティ」を拡張するクラスだけがレイアウトを処理できますか?
ご清聴ありがとうございました。