vendredi 24 août 2018

Design Pattern not working with OnClickListener

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) {
                           performDialogOkAction(response);
                           dialogs.clearAll();
                       }
                  }, 
                  new View.OnClickListener() {
                     @Override
                         public void onClick(View view) {
                             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 ?

Aucun commentaire:

Enregistrer un commentaire