java - How does an interface communicate - Need a detailed answer -


i have fragment class:

public class uploadfragmentone extends fragment {} 

i have subclassed:

 public interface communicator {         void communicate(int position);     } 

in oncreateview:

 ((communicator) getactivity()).communicate(1); 

the hosting activity signature:

public class detailspager extends fragmentactivity implements uploadfragmentone.communicator {}  

member function in above activity:

 public void communicate(int position) {         toast.maketext(detailspager.this, "clicked " + position, toast.length_long).show();     } 

this works charm, dont understand how? sorry might dumb, want know how control flows in this?

you should have on following link once.- come query

(myactivity)activity.some_method() 

now suppose going attach same fragment activity mainactivity need -

(mainactivity)activity.some_method() 

now suppose other activity implementing same fragment each time need use instanceof check , call method , add it.

again suppose trivial case when going create library , going offer result delivery particular event then? how instance type ?

interface name suggests offer way communicated without actual class instance. need implemented. can have on onclicklistener in view class of android api sources.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -