Android fragment实现按钮点击事件的示例讲解
时间: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)); } }); }
栏 目:Android代码
下一篇:Android 通过webservice上传多张图片到指定服务器详解
本文标题:Android fragment实现按钮点击事件的示例讲解
本文地址:http://www.codeinn.net/misctech/174175.html