时间:2021-09-11 08:09:13 | 栏目:Android代码 | 点击:次
fragment无法直接进行点击事件,需要放到oncreatActivity中
代码如下:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_first, null); return view; }
点击事件代码:
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Button sweepButton = (Button) getActivity().findViewById(R.id.image1); sweepButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getActivity(), "nihao", Toast.LENGTH_LONG).show(); //从fragment跳转到activity中 startActivity(new Intent(getActivity(), PayMoneyActivity.class)); } }); }