public class Fragment2 extends fragments {
Private Button BTN.
@ Nullable
@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View the View=inflater. Inflate (R.l ayout. Fragment2, container, false);
Return the view;
}
@ Override
Public void onActivityCreated (@ Nullable Bundle savedInstanceState) {
Super. OnActivityCreated (savedInstanceState);
BTN=(Button) getActivity (). The findViewById (R.i which est_bt);
BTN. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View View) {
Toast. MakeText (getContext (), "success2", Toast. LENGTH_SHORT), show ();
StartActivity (new Intent (getActivity (), PayActivity. Class));
}
});
}
}
CodePudding user response:
Fragments need getActivity (). StartActivity (new Intent (getActivity (), PayActivity. Class));CodePudding user response:
Why the activity of the button to set the click event at the fragments? If it is a fragment of the button, you should set the click event in onViewCreated methodCodePudding user response: