android - Java object notify parent class -


i developing app in android. have 1 class called augmentedview, extends , responsible draw markers. in ondraw method when detects collisions want notify parent class main class , contains main gui enable 1 button in screen. call augmentedview class in oncreate of main class following code:

    augmentedview augmentedview = new augmentedview(this);     augmentedview.setontouchlistener(this);     augmentedview.setlayoutparams(new layoutparams(             layoutparams.wrap_content, layoutparams.wrap_content));     livelayout.addview(augmentedview); 

how can notify main class changes , pass list of markers it?

if i'm understanding problem correctly , want notify activity/fragment contains augmentedview.

a simple way using java callbacks.

// in activity

 //oncreate() ..  augmentedview augmentedview = new augmentedview(this); augmentedview.setontouchlistener(this); augmentedview.setcollisionlistener(new collisionlistener()); augmentedview.setlayoutparams(new layoutparams(         layoutparams.wrap_content, layoutparams.wrap_content)); livelayout.addview(augmentedview);  }  .. public class collisionlistener {     public void oncollosion (){      // write code handle collosion     }  }       // in augmentedview      private collisionlistener mlistener;      public void setcollisionlistener(collisionlistener listener){         mlistener = listener;     }      public void ondraw(canvas canvas){     // code     if (collosiondetected && mlistener != null) {         mlistener.oncollosion();     }      }  

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -