Таким образом, проблема заключалась в том, чтобы сообщить диалогу dismiss (), когда я не находился в области, в которой этот диалог существовал. Вот мое решение:
Создайте OnTouchListener в той же области, что и диалоговое окно - в данном случае, в моей основной деятельности. Затем передайте его при инициализации диалогового окна, которое, в свою очередь, должно передать его группе просмотра.
Это будет выглядеть примерно так:
код активности:
public class My_Activity extends Activity {
public Custom_Dialog my_dialog;
...
public void onCreate(Bundle savedInstanceState) {
OnTouchListener otl_custom_dialog = new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
if ( logic checking if the user has clicked the button area ) {
//notice I can still access any _public_ variable within the viewgroup class
//by using my_dialog.my_custom_viewgroup.public_variable
...
//I can now call dismiss() from within this scope
my_dialog.dismiss();
}
...
}
}
...
//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(), otl_custom_dialog);
my_dialog.show();
}
}
код диалога:
public class Custom_Dialog extends Dialog {
Custom_ViewGroup my_custom_viewgroup;
OnTouchListener otl_custom_dialog;
...
public void onCreate(Bundle savedInstanceState) {
...
setContentView(new Custom_ViewGroup(context, class_that_im_editing, otl_custom_dialog));
}
}
код группы просмотра:
public class Custom_ViewGroup extends ViewGroup implements OnTouchListener {
public Custom_ViewGroup(Context context, Class_That_Im_Editing class_that_im_editing, OnTouchListener otl_custom_dialog) {
...
this.setOnTouchListener(otl_custom_dialog);
}
}
Я проверил этот метод, и он отлично работает. Надеюсь, это поможет кому-то еще!