Android - Why should I implement an interface when communicating between the main action and the fragment

I do not understand anything. Now I read the documents on the Android developers site and it says that in order to communicate with fragments I have to implement an interface. However, now I can easily access widgets that exist on the fragment in the Main activitiy class.

For example, in the main activity class, by issuing the following line, I can access the text element of the fragment.

TextView t1 = (TextView) findViewById(R.id.t1);

In this state, why do I need to implement an interface? (forgive my ignorance and thanks)

+4
source share
1 answer

Fragment, Activity, ? getActivity(), , Activity, .

, Java, , Activity, , , , MyActivity, , , Activity ActionBarActivity. ((MyActivity)getActivity()).myMethod();

, . , , MyActivity.

, myMethod() interface Activity . Activity, , , .

+4

All Articles