android - Pass a listener to a method that creates View with this listener issue -
this situation: want pass listener view generator using it. problem in listener want use view data. how twisted... way pre-define view interface listener should attach to?
adapterview.onitemselectedlistener listener = new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> adapterview, view view, int pos, long l) { //but can not , use spinner cause not defined string text = spinner.getselectedstrings().tostring(); } @override public void onnothingselected(adapterview<?> adapterview) {} }; generatespinner(attributes, listener);
i'm working on mvc project in android , issue come out there, cause should separate creation , logic view , presenter. presenter force view generate spinner given logic.
you have answered more half of question yourself. make interface this:
public interface myviewcallback { void run(view view); }
now, can store instance of interface
, call run()
method view
's scope whenever need - example,
myviewcallback callback; // ... on action callback.run(this);
you can create setter callback
, use register callback.
Comments
Post a Comment