android - static inner class and non static outer method -


i have problem colorpickerdialog http://www.yougli.net/android/a-photoshop-like-color-picker-for-your-android-application/

this colorpickerdialog has inner static class... in inner static class need use "close()" or "dismiss()" on colorpickerdialog close it...

my problem public class colorpickerdialog extends dialog

the close() , dismiss() methods non static in dialog. how can use methods in inner static class private static class colorpickerview extends view ?

edit... here important sections code..

public class colorpickerdialog extends dialog {  public interface oncolorchangedlistener {     void colorchanged(string key, int color); }  private static class colorpickerview extends view {     @override     public boolean ontouchevent(motionevent event) {         if (x > 266 && x < 394 && y > 316 && y < 356){             saveddialog();         }         return true;     }      private void saveddialog() {         new alertdialog.builder(getcontext())         .settitle("save profile?")         .setpositivebutton("yes",                 new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog,                             int which) {                     }                 })         .setnegativebutton("no",                 new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog,                             int which) {                     }                 }).show();      } }  public colorpickerdialog(context context, oncolorchangedlistener listener,         string key, int initialcolor, int defaultcolor) {     super(context);      mlistener = listener;     mkey = key;     minitialcolor = initialcolor;     mdefaultcolor = defaultcolor; }  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     oncolorchangedlistener l = new oncolorchangedlistener() {         public void colorchanged(string key, int color) {             mlistener.colorchanged(mkey, color);             dismiss();         }     };      setcontentview(new colorpickerview(getcontext(), l, minitialcolor,             mdefaultcolor));     settitle(r.string.pick_a_color);  } } 

and here intatiate colorpickerdialog...

public class lampsfragment extends fragment {  @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     lv.setonitemlongclicklistener(new adapterview.onitemlongclicklistener() {         @override         public boolean onitemlongclick(adapterview<?> arg0, view arg1,                 int arg2, long arg3) {             oncolorchangedlistener listener = new oncolorchangedlistener() {                  @override                 public void colorchanged(string key, int color) {                   }             };             colorpickerdialog cp = new colorpickerdialog(getactivity(), listener, key, arg2, arg2);             cp.show();             return false;         }     });      lv.setadapter(files);      return view; }  } 

i want close colorpickerdialog after pressing "yes" on alertdialog the inner static class.

you can't, unless can instance of colorpickerdialog somehow. static modifier on inner class strictly required? static inner classes not have access instances of surrounding class. can either make colorpickerview member class (non-static inner class), or pass reference surrounding class (either in constructor or via setter method call).

member classes have implicit reference surrounding instance, , can make call methods of surrounding classes directly. if there name-hiding; ex. suppose colorpickerview declares close() method, can call outer-class method colorpickerdialog.this.close().


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -