QUESTION:
1. The onClick XML attribute will call the active activity method.
2. The raw public method.
3. Reuse of fragments.
DECISION:
In the Fragment Layout, add it to the view.
android:onClick="onFragmentViewClick"
In each activity, a fragment may belong ..
public void onFragmentViewClick(View v) { Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.container); if (fragment != null && fragment.isVisible()) { if (fragment instanceof SomeFragment) { ((SomeFragment) fragment).onViewClicked(v); } } }
In the Snippet, enable this method.
public void onViewClicked(View v) { switch (v.getId()) { case R.id.view_id: Log.e("onViewClicked", "yehhh!!"); break; } }
Sjd Dec 23 '15 at 11:18 2015-12-23 11:18
source share