contentview がカスタム ビューグループであるカスタム ダイアログ (Dialog を拡張) があります。ビューグループには edittext の子がいくつかありますが、ビューグループの dispatchDraw および onTouch メソッドでボタンの描画とクリックを自分で処理しています (できるだけ多くのビューを膨張させないようにしています)。具体的には、このビューには、ダイアログの閉じるボタンとして設定できるボタンの子がありません。viewgroup の onTouch メソッド内からダイアログを閉じたいのですが、戻るキーを押すことをシミュレートする以外に、これを行う方法がわかりません。
活動コード:
public class My_Activity extends Activity {
...
public void onCreate(Bundle savedInstanceState) {
...
//if there's no Class_That_Im_Editing in the database, prompt the user to make a new one by adding information to the editviews in this custom dialog and clicking the area where I draw the ok button
my_dialog = new Custom_Dialog(this, R.style.CustomDlg, new Class_That_Im_Editing());
}
}
ダイアログコード:
public class Custom_Dialog extends Dialog {
...
public void onCreate(Bundle savedInstanceState) {
...
setContentView(new Custom_ViewGroup(context, Class_That_Im_Editing));
}
}
ビューグループ コード:
public class Custom_ViewGroup extends ViewGroup implements OnTouchListener {
//this class has some edittext children but _no_ buttons
...
public boolean onTouch(View view, MotionEvent event) {
if ( logic checking if the user has clicked the button area ) {
//??? what do I put here to dismiss the dialog
}
}
}
私が考えることができる他の唯一のアプローチは、onCreateDialog および onPrepareDialog イベント ハンドラーをオーバーライドすることを意味する、dismissDialog(int) メソッドを使用することです。しかし、ビューの onTouch メソッド内から DismissDialog を呼び出すにはどうすればよいでしょうか?
たぶん、ある種のリスナーを設定する必要がありますか?もしそうなら、これを行うためのスケルトンコードは何でしょうか?