I am trying to develop a abstract OnClickListener caller for all my dialog boxes.
public abstract class A {
public void handleError() {
if (dialogs != null && activity != null) {
final String mNoxMessages[] = God.getMnoxMessage((Context) activity, response);
((Activity) activity).runOnUiThread(new Thread
(new Runnable() {
public void run() {
dialogs.showDialogForMessage("title", "description",
"ok", "cancel",
new View.OnClickListener() {
@Override
public void onClick(View view) {
//breakpoint location here never reaches
performDialogOkAction(response);
dialogs.clearAll();
}
},
new View.OnClickListener() {
@Override
public void onClick(View view) {
//breakpoint location here never reaches
performDialogCancelAction(response);
dialogs.clearAll();
}
}
}));
);}
}
public abstract void performDialogOkAction(Object errorCode);
public abstract void performDialogCancelAction(Object errorCode);
}
public void showDialogForMessage(String title, String description,
String okButtonText, String cancelButtonText,
View.OnClickListener okOnClick,
View.OnClickListener cancelOnClick) {
ok = informationDialog.findViewById(R.id.information_ok);
cancel = informationDialog.findViewById(R.id.information_cancel);
ok.setText(okButtonText);
cancel.setText(cancelButtonText);
ok.setOnClickListener(okOnClick);
cancel.setOnClickListener(cancelOnClick);
}
public class B extends A {
@Override
public void performDialogOkAction(Object errorCode) {
//breakpoint location here never reaches
}
}
When I click the button, the control never goes to the performDialogOkAction
method at all.
What am I missing here ?
dialogs
?setOnClickListener
is called..B
, or whatinformationDialog
is or where it's created and shown, or howA
has access toresponse
, even though it's not declared anywhere, etc. Honestly, in its current form, this design seems a little convoluted. Have you considered subclassingDialog
orDialogFragment
and handling all this there?