I have many buttons declared in an xml layout file, and use this layout for a fragment.
button android:id="@+id/button1" android:onClick="onClickButton"/> button android:id="@+id/button2" android:onClick="onClickButton"/> .... button android:id="@+id/buttonN" android:onClick="onClickButton"/>
It's disappointed that "onClickButton" events are catched in the host activity, not in my fragment. Of course, in my fragment I can manually solve this problem as follow:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_content, container, false); Button button1 = (Button) view.findViewById(R.id.button1); button1.setOnClickListener(...); ... etc Button buttonN = (Button) view.findViewById(R.id.buttonN); buttonN.setOnClickListener(...);
is there any explicit way to handle onClickbutton events in Fragment?